我有完全相同的問題,不能用DotNetOpenAuth
解決它,不管是我的嘗試。當使用DotNetOpenAuth
時,Twitter的身份驗證過程要比Facebook或Google+更難獲取。經過許多令人沮喪的時間,加密和編碼數據的各個部分的次數不盡相同,並且始終使無用的401未經授權,我將Tweetsharp添加到混合中,並創建了我自己的IAuthenticationClient
進行Twitter身份驗證。使用Tweetsharp
進行身份驗證非常簡單。它成爲這個相對小事:
在你TwitterClient
構造:
var twitterService = new TwitterService(consumerKey, consumerSecret);
在你執行IAuthenticationClient
:
public void RequestAuthentication(HttpContextBase context, Uri returnUrl)
{
var requestToken = twitterService.GetRequestToken(returnUrl.AbsoluteUri);
var redirectUrl = twitterService.GetAuthorizationUri(requestToken).AbsoluteUri;
context.Response.Redirect(redirectUrl, true);
}
public AuthenticationResult VerifyAuthentication(HttpContextBase context)
{
var oAuthToken = context.Request.QueryString["oauth_token"];
var oAuthVerifier = context.Request.QueryString["oauth_verifier"];
var requestToken = new OAuthRequestToken { Token = oAuthToken };
var accessToken = twitterService.GetAccessToken(requestToken, oAuthVerifier);
twitterService.AuthenticateWith(accessToken.Token, accessToken.TokenSecret);
var user = twitterService.VerifyCredentials();
var userId = user.Id.ToString();
var extraData = new Dictionary<string, string>
{
{"accesstoken", accessToken.Token},
{"accesstokensecret", accessToken.TokenSecret},
{"id", userId},
{"name", user.Name},
{"username", user.ScreenName},
{"link", user.Url},
};
return new AuthenticationResult(true, ProviderName, userId, user.ScreenName, extraData);
}
我與此項目無關,但它看起來像DotNetOpenAuth([WorldDomination.Web.Authentication](https://github.com/PureKrome/) WorldDomination.Web.Authentication)) –
另外,爲了回答你的問題,我們需要'seez teh codez'。 –
這是不是任何代碼...以及身份驗證配置中的2行OAuthWebSecurity.RegisterTwitterClient – David