Using iOS 6 social.Framework (twitter oauth) to lo

2019-08-03 17:52发布

问题:

I have a site built using ASP.NET MVC 4 with its built-in login OAuth integration to Twitter.

I also have an iOS native app that uses social.Framework and twitter's reverse auth to get an oauth token+secret for a twitter account stored on the device.

How can use the iOS credentials to pages and web services hosted on my ASP.NET MVC 4 site?

回答1:

  1. In AccountController.cs, clone ExternalLoginCallback action method with a different url and add oath_token and oauth_token_secret method parameters.
  2. Remove the VerifyAuthentication call and check.
  3. Check to see if User.Identity.IsAuthenticated, if so, WebSecurity.Logout() and return Redirect(Request.Url.ToString()).
  4. Call Twitter's /account/verify_credentials.json (signed) to validate the oauth token and get the screen_name. Make sure you use RFC3896 encoding (eg. %2B not %2b) or it won't work.
  5. Replace result.Provider with "twitter".
  6. Replace result.ProviderUserId with screen_name.