public override IClaimsIdentity ProcessSignInResponse(string realm, string originalUrl, HttpContextBase httpContext) { var client = new GoogleOpenIdClient(); AuthenticationResult result; try { result = client.VerifyAuthentication(httpContext); } catch (WebException wex) { throw new InvalidOperationException(new StreamReader(wex.Response.GetResponseStream()).ReadToEnd(), wex); } var claims = new List<Claim> { new Claim(System.IdentityModel.Claims.ClaimTypes.NameIdentifier, result.ExtraData["email"]) }; foreach (var claim in result.ExtraData) { claims.Add(new Claim("http://schemas.google.com/" + claim.Key, claim.Value)); } return new ClaimsIdentity(claims, "Google"); }
// Point Login URL to this Action public ActionResult Login() { DotNetOpenAuth.AspNet.Clients.GoogleOpenIdClient client = new GoogleOpenIdClient(); UrlHelper helper = new UrlHelper(this.ControllerContext.RequestContext); var result = helper.Action("Presentations", "Features", null, "http"); client.RequestAuthentication(this.HttpContext, new Uri(result)); return new EmptyResult(); }
public static void RegisterAuth() { // To let users of this site log in using their accounts from other sites such as Microsoft, Facebook, and Twitter, // you must update this site. For more information visit http://go.microsoft.com/fwlink/?LinkID=252166 // Use MicrosoftClientEx class instead of MicrosoftClient, because to retrieve e-mail address. var microsoftClient = new MicrosoftClientEx( appId: AppSettings.MicrosoftAccount_ClientId, appSecret: AppSettings.MicrosoftAccount_ClientSecret, requestedScopes: new[] { "wl.emails" }); OAuthWebSecurity.RegisterClient(microsoftClient, microsoftClient.ProviderName, null); // Hack: Fix unmatch of google client provider name and display name upper/lower case, // but ProviderName property is read only, so I hacked this by reflection. var googleClient = new GoogleOpenIdClient(); googleClient.ToDynamic().providerName = "Google"; OAuthWebSecurity.RegisterClient(googleClient, googleClient.ProviderName, null); }
/// <summary> /// Registers a supported OpenID client /// </summary> public static void RegisterOpenIDClient(BuiltInOpenIDClient openIDClient) { IAuthenticationClient client; switch (openIDClient) { case BuiltInOpenIDClient.Google: client = new GoogleOpenIdClient(); break; case BuiltInOpenIDClient.Yahoo: client = new YahooOpenIdClient(); break; default: throw new ArgumentOutOfRangeException("openIDClient"); } RegisterClient(client); }
// // GET: /Account/Google public ActionResult Google() { var googleClient = new GoogleOpenIdClient(); return Authenticate(googleClient); }
public override void ProcessSignInRequest(Scope scope, HttpContextBase httpContext) { var client = new GoogleOpenIdClient(); client.RequestAuthentication(httpContext, this.MultiProtocolIssuer.ReplyUrl); }