C#Asp.net Linkedin授权使用Linkedintoolkit和DotNetOpenAuth
我试图授权我的ASP.net应用程序使用LinkdinAPI,但似乎无法正确验证。我希望有人能看看我的源代码,看看我可能做错了什么 首先,我试着按照这些步骤来做,虽然我在按照这些步骤做,但还是没有运气 按照我的理解,最简单的过程如下C#Asp.net Linkedin授权使用Linkedintoolkit和DotNetOpenAuth,c#,asp.net,oauth,linkedin,oauth-provider,C#,Asp.net,Oauth,Linkedin,Oauth Provider,我试图授权我的ASP.net应用程序使用LinkdinAPI,但似乎无法正确验证。我希望有人能看看我的源代码,看看我可能做错了什么 首先,我试着按照这些步骤来做,虽然我在按照这些步骤做,但还是没有运气 按照我的理解,最简单的过程如下 创建DotNetOpenAuth的IConsumerTokenManager的实现 使用WebOAuthAuthorization类对我的应用程序进行授权,并为将来的API调用返回访问令牌 我的IConsumerTokenManager实现如下所示 出于显而易见的原
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
namespace UserLibrary.SocialMedia
{
public class ConsumerTokenManager : IConsumerTokenManager
{
private const string API_KEY = "ylk7j2jq4j7l";
private const string SECRET_KEY = "WH3dlPFhPyWG0xlw";
private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
public ConsumerTokenManager()
{
ConsumerKey = API_KEY;
ConsumerSecret = SECRET_KEY;
}
#region ITokenManager Members
public string ConsumerKey { get; private set; }
public string ConsumerSecret { get; private set; }
public string GetTokenSecret(string token)
{
return this.tokensAndSecrets[token];
}
public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response)
{
this.tokensAndSecrets[response.Token] = response.TokenSecret;
}
public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret)
{
this.tokensAndSecrets.Remove(requestToken);
this.tokensAndSecrets[accessToken] = accessTokenSecret;
}
/// <summary>
/// Classifies a token as a request token or an access token.
/// </summary>
/// <param name="token">The token to classify.</param>
/// <returns>Request or Access token, or invalid if the token is not recognized.</returns>
public TokenType GetTokenType(string token)
{
throw new NotImplementedException();
}
#endregion
}
}
ConsumerTokenManager consumerTokenManager = new ConsumerTokenManager();
_webOAuthorization = new WebOAuthAuthorization(consumerTokenManager, _accessToken);
_webOAuthorization.BeginAuthorize();
_accessToken = _webOAuthorization.CompleteAuthorize();