protected override void ProcessCore(IdentityProvidersArgs args) { Assert.ArgumentNotNull(args, "args"); IdentityProvider = this.GetIdentityProvider(); var provider = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationProvider { OnAuthenticated = (context) => { //map claims context.Identity.ApplyClaimsTransformations(new TransformationContext(this.FederatedAuthenticationConfiguration, IdentityProvider)); return(Task.CompletedTask); } }; var googleAuthOptions = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions { ClientId = ClientId, ClientSecret = ClientSecret, Provider = provider, AuthenticationType = IdentityProvider.Name }; args.App.UseGoogleAuthentication(googleAuthOptions); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); //app.UseFacebookAuthentication( // appId: "", // appSecret: ""); Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions option = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions(); option.CallbackPath = new PathString("/signin-google"); option.ClientId = System.Configuration.ConfigurationSettings.AppSettings["GoogleClientKey"]; option.ClientSecret = System.Configuration.ConfigurationSettings.AppSettings["GoogleClientSecret"]; app.UseGoogleAuthentication(option); }
// For more information on configuring authentication, please visit http://go.microsoft.com/fwlink/?LinkId=301864 public void ConfigureAuth(IAppBuilder app) { // Enable the application to use a cookie to store information for the signed in user app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login") }); // Use a cookie to temporarily store information about a user logging in with a third party login provider app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Uncomment the following lines to enable logging in with third party login providers //app.UseMicrosoftAccountAuthentication( // clientId: "", // clientSecret: ""); //app.UseTwitterAuthentication( // consumerKey: "", // consumerSecret: ""); app.UseFacebookAuthentication( appId: "395662430833670", appSecret: "4acfb0e8d9901f2c6846f1dd60910c0a"); var googleOAuth2AuthenticationOptions = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions { ClientId = "852013154203-somq7hs1p5makagbrq1fjuked4qofb0a.apps.googleusercontent.com", ClientSecret = "Qs1QLTNwAsLc-6Rmeg5GcKnr", }; app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions); }
public virtual void ConfigureAdditionalIdentityProviders(IAppBuilder app, string signInAsType) { app.Use(async(ctx, next) => { Preprocess(ctx); await next(); Postprocess(ctx); }); var google = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions { AuthenticationType = "Google", SignInAsAuthenticationType = signInAsType, ClientId = "foo", ClientSecret = "bar" }; app.UseGoogleAuthentication(google); }
public void GetLogin_EnableLocalLoginMoreThanOneProvider_ShowsLoginPage() { Action <IAppBuilder, string> config = (app, name) => { base.ConfigureAdditionalIdentityProviders(app, name); var google = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions { AuthenticationType = "Google2", Caption = "Google2", SignInAsAuthenticationType = Constants.ExternalAuthenticationType, ClientId = "foo", ClientSecret = "bar" }; app.UseGoogleAuthentication(google); }; OverrideIdentityProviderConfiguration = config; this.Init(); options.AuthenticationOptions.EnableLocalLogin = false; var resp = GetLoginPage(); resp.AssertPage("login"); }
public void Configuration(IAppBuilder app) { //app.CreatePerOwinContext(ApplicationDbContext.Create); //app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); //app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = "ApplicationCookie", LoginPath = new PathString("/auth/login") }); DataProtectionProvider = app.GetDataProtectionProvider(); app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie); // Enables the application to temporarily store user information when they are verifying the second factor in the two-factor authentication process. app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5)); if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("FacebookAppId"))) { var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions { AppId = ConfigurationManager.AppSettings.Get("FacebookAppId"), AppSecret = ConfigurationManager.AppSettings.Get("FacebookAppSecret"), Provider = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationProvider { OnAuthenticated = (context) => { context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:access_token", context.AccessToken, XmlSchemaString, "Facebook")); //context.Identity.AddClaim(new System.Security.Claims.Claim("urn:facebook:email", context.Email, XmlSchemaString, "Facebook")); foreach (var x in context.User) { var claimType = string.Format("urn:facebook:{0}", x.Key); string claimValue = x.Value.ToString(); if (!context.Identity.HasClaim(claimType, claimValue)) { context.Identity.AddClaim(new System.Security.Claims.Claim(claimType, claimValue, XmlSchemaString, "Facebook")); } } return(Task.FromResult(0)); } } }; facebookOptions.Scope.Add("email"); app.UseFacebookAuthentication(facebookOptions); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("TwitterAppId"))) { var twitterOptions = new Microsoft.Owin.Security.Twitter.TwitterAuthenticationOptions { ConsumerKey = ConfigurationManager.AppSettings.Get("TwitterAppId"), ConsumerSecret = ConfigurationManager.AppSettings.Get("TwitterAppSecret"), BackchannelCertificateValidator = new CertificateSubjectKeyIdentifierValidator(new[] { "A5EF0B11CEC04103A34A659048B21CE0572D7D47", "0D445C165344C1827E1D20AB25F40163D8BE79A5", "7FD365A7C2DDECBBF03009F34339FA02AF333133", "39A55D933676616E73A761DFA16A7E59CDE66FAD", "5168FF90AF0207753CCCD9656462A212B859723B", "B13EC36903F8BF4701D498261A0802EF63642BC3" }), Provider = new Microsoft.Owin.Security.Twitter.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(twitterOptions); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("GoogleAppId"))) { var GoogleOptions = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationOptions { ClientId = ConfigurationManager.AppSettings.Get("GoogleAppId"), ClientSecret = ConfigurationManager.AppSettings.Get("GoogleAppSecret"), //SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie, Provider = new Microsoft.Owin.Security.Google.GoogleOAuth2AuthenticationProvider { OnAuthenticated = (context) => { context.Identity.AddClaim(new System.Security.Claims.Claim("urn:google:access_token", context.AccessToken, XmlSchemaString, "Google")); context.Identity.AddClaim(new System.Security.Claims.Claim("First_Name", context.GivenName, XmlSchemaString, "Google")); context.Identity.AddClaim(new System.Security.Claims.Claim("Last_Name", context.FamilyName, XmlSchemaString, "Google")); context.Identity.AddClaim(new System.Security.Claims.Claim("Email", context.Email, XmlSchemaString, "Google")); return(Task.FromResult(0)); } } }; app.UseGoogleAuthentication(GoogleOptions); } if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings.Get("LinkedInAppId"))) { var LinkedInOptions = new Owin.Security.Providers.LinkedIn.LinkedInAuthenticationOptions { ClientId = ConfigurationManager.AppSettings.Get("LinkedInAppId"), ClientSecret = ConfigurationManager.AppSettings.Get("LinkedInAppSecret"), Provider = new Owin.Security.Providers.LinkedIn.LinkedInAuthenticationProvider { OnAuthenticated = (context) => { context.Identity.AddClaim(new System.Security.Claims.Claim("urn:google:access_token", context.AccessToken, XmlSchemaString, "LinkedIn")); context.Identity.AddClaim(new System.Security.Claims.Claim("First_Name", context.GivenName, XmlSchemaString, "LinkedIn")); context.Identity.AddClaim(new System.Security.Claims.Claim("Last_Name", context.FamilyName, XmlSchemaString, "LinkedIn")); context.Identity.AddClaim(new System.Security.Claims.Claim("Email", context.Email, XmlSchemaString, "LinkedIn")); context.Identity.AddClaim(new System.Security.Claims.Claim("Company", context.Positions, XmlSchemaString, "LinkedIn")); return(Task.FromResult(0)); } } }; app.UseLinkedInAuthentication(LinkedInOptions); } }