![](/img/trans.png)
[英]Can we embed authorization for twitter, linkedin, facebook, buzz in asp.net c# web application?
[英]C# Asp.net Linkedin authorization using Linkedintoolkit with DotNetOpenAuth
我试图授权我的ASP.net应用程序使用Linkdin API,但似乎无法正确进行身份验证。 我希望有人可以看看我的源代码,看看我可能做错了什么。
首先,我正在尝试遵循Linkedintoolkit文档中的步骤,尽管我在遵循这些步骤,但仍然没有运气。
据我了解,最简单的过程如下。
我的IConsumerTokenManager实现如下
在此示例中,出于明显的原因,我添加了伪造的api密钥和秘密密钥
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
}
}
这是调用BeginAuthorization的代码块
ConsumerTokenManager consumerTokenManager = new ConsumerTokenManager();
_webOAuthorization = new WebOAuthAuthorization(consumerTokenManager, _accessToken);
_webOAuthorization.BeginAuthorize();
_accessToken = _webOAuthorization.CompleteAuthorize();
当调用“ BeginAuthorization()”时,我被重定向到“授予K2PS发布者对您的LinkedIn帐户“ Patrick A”的访问权限,仅当您使用LinkedIn网络信息信任此应用程序时才允许访问” Linkedin页面,然后单击“确定,我会允许它使我返回到我的网络应用程序。 但是,永远不会命中'_completeAuthorization()'方法,如果我尝试返回字符串,则它的值为null。
还要注意的是,我的控制台输出在此过程中引发了Threading异常。
下面是我的控制台的副本
mscorlib.dll中发生类型'System.Threading.ThreadAbortException'的第一次机会异常mscorlib.dll中发生类型'System.Threading.ThreadAbortException'的异常,但未在用户代码中处理
我对Oath相当陌生,但是一直在使用API,似乎无法解决这个问题。 任何帮助将不胜感激。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.