After testing the embedded MVC 5 OAuth2 / OpenID providers, I was able to create a website that allowed me to authenticate myself using my Twitter credentials.
The problem that I am currently facing is that I also want to save the tokens (oauth_token and oauth_verifier) ββon Twitter after the user has successfully authenticated. I need these tokens, so I can allow users to post data directly from my site to their Twitter account.
After setting TwitterAuthenticationOptions (see below) in Startup.Auth.cs, I found that the tokens that I follow can be found in the context (((context.Response.Context).Request).QueryString) , but parsing this seems ugly decision.
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);
How can this be gracefully implemented? For Facebook, I found a solution that actually extracts additional information, this is similar to ...
get-more-information-from-social-providers-used-in-the-vs-2013-project-templates
c # asp.net-mvc asp.net-mvc-5 twitter
Frank
source share