Skip to content

Instantly share code, notes, and snippets.

@benfoster
Created May 3, 2012 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benfoster/2586265 to your computer and use it in GitHub Desktop.
Save benfoster/2586265 to your computer and use it in GitHub Desktop.
Using the clients from DotNetOpenAuth.AspNet in ASP.NET MVC
[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