在测试了内置的MVC 5 OAuth2/OpenID提供程序后,我能够创建一个网站,允许我使用我的Twitter凭据进行身份验证.
我现在遇到的问题是,我还想在用户成功通过身份验证后,在网址中存储令牌(oauth_token和oauth_verifier)Twitter帖子.我需要这些令牌,所以我可以允许用户直接从我的网站发布详细信息到他们的Twitter帐户.
在Startup.Auth.cs中设置了TwitterAuthenticationOptions(见下文)后,我确实发现我所关注的令牌可以在上下文中找到,但解析这似乎是一个丑陋的解决方案.(((context.Response.Context).Request).QueryString)
var tw = new TwitterAuthenticationOptions { ConsumerKey = "SecretKey", ConsumerSecret = "SecretSecret", SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie, Provider = new TwitterAuthenticationProvider() { OnAuthenticated = (context) => { context.Identity.AddClaim(new System.Security.Claims.Claim("urn:twitter:access_token", context.AccessToken, XmlSchemaString, "Twitter")); return Task.FromResult(0); } } }; app.UseTwitterAuthentication(tw);
如何优雅地实施?对于Facebook我找到了一个实际检索其他信息的解决方案,这感觉类似......
获得-更多信息从 - 社会提供商使用的,在最VS-2013项目模板