Created
May 3, 2012 14:57
-
-
Save benfoster/2586265 to your computer and use it in GitHub Desktop.
Using the clients from DotNetOpenAuth.AspNet in ASP.NET MVC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
public void OAuth(string provider, string returnUrl) | |
{ | |
var client = OAuthHelper.GetOAuthClient(provider); | |
client.RequestAuthentication( | |
HttpContext, | |
new Uri(Url.QualifyAction("OAuthCallback", "Auth", new { provider = provider, returnUrl = returnUrl })) | |
); | |
} | |
[HttpGet] | |
public ActionResult OAuthCallback(string provider, string returnUrl) | |
{ | |
var client = OAuthHelper.GetOAuthClient(provider); | |
var result = client.VerifyAuthentication(HttpContext); | |
if (result.IsSuccessful) | |
{ | |
// check if we have a user | |
var user = membership.FindUserWithLogin(AuthenticationProviders.Twitter, result.ProviderUserId); | |
if (user == null) // if not, register them | |
{ | |
// meh | |
} | |
// sign them in | |
return SignInAndRedirect(user, AuthenticationProviders.Twitter, returnUrl, createPersistentCookie: true); | |
} | |
return new EmptyResult(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment