protected override void ProcessCore(IdentityProvidersArgs args) { Assert.ArgumentNotNull(args, nameof(args)); IdentityProvider = this.GetIdentityProvider(); var provider = new Auth0AuthenticationProvider { OnAuthenticated = (context) => { context.Identity.ApplyClaimsTransformations(new Owin.Authentication.Services.TransformationContext(this.FederatedAuthenticationConfiguration, IdentityProvider)); return(Task.CompletedTask); }, OnReturnEndpoint = (context) => { return(Task.CompletedTask); } }; var auth0options = new Auth0AuthenticationOptions { ClientId = Configuration.Settings.GetSetting("FedAuth.Auth0.ClientId"), ClientSecret = Configuration.Settings.GetSetting("FedAuth.Auth0.ClientSecret"), Provider = provider, Domain = Configuration.Settings.GetSetting("FedAuth.Auth0.Domain"), AuthenticationType = IdentityProvider.Name, CallbackPath = new PathString("/signin-auth0"), }; args.App.UseAuth0Authentication(auth0options); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters string auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; string auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; string auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Enable Kentor Cookie Saver middleware app.UseKentorOwinCookieSaver(); // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); // Configure Auth0 authentication var options = new Auth0AuthenticationOptions() { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, }; options.Scope.Add("openid profile"); // Request a refresh_token app.UseAuth0Authentication(options); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters var auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; var auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; var auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); // Configure Auth0 authentication var options = new Auth0AuthenticationOptions { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, // Save the tokens to claims SaveIdToken = true, SaveAccessToken = true, SaveRefreshToken = true }; options.Scope.Add("offline_access"); // Request a refresh_token app.UseAuth0Authentication(options); // Turn on SignalR listening app.MapSignalR(); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters string auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; string auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; string auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Enable Kentor Cookie Saver middleware app.UseKentorOwinCookieSaver(); // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); // Configure Auth0 authentication var options = new Auth0AuthenticationOptions() { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, Provider = new Auth0AuthenticationProvider { OnAuthenticated = context => { // Get the user's country JToken countryObject = context.User["https://schemas.quickstarts.com/country"]; if (countryObject != null) { string country = countryObject.ToObject <string>(); context.Identity.AddClaim(new Claim("country", country, ClaimValueTypes.String, context.Connection)); } // Get the user's roles var rolesObject = context.User["https://schemas.quickstarts.com/roles"]; if (rolesObject != null) { string[] roles = rolesObject.ToObject <string[]>(); foreach (var role in roles) { context.Identity.AddClaim(new Claim(ClaimTypes.Role, role, ClaimValueTypes.String, context.Connection)); } } return(Task.FromResult(0)); } } }; app.UseAuth0Authentication(options); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters string auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; string auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; string auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Enable Kentor Cookie Saver middleware app.UseKentorOwinCookieSaver(); // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); // Configure Auth0 authentication var options = new Auth0AuthenticationOptions() { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, //SaveIdToken = true, //SaveAccessToken = true, //SaveRefreshToken = true, // If you want to request an access_token to pass to an API, then replace the audience below to // pass your API Identifier instead of the /userinfo endpoint Provider = new Auth0AuthenticationProvider() { OnApplyRedirect = context => { string userInfoAudience = $"https://{auth0Domain}/userinfo"; string redirectUri = context.RedirectUri + "&audience=" + WebUtility.UrlEncode(userInfoAudience); context.Response.Redirect(redirectUri); } } }; //This adds the email to the custom claims options.Scope.Add("email"); //For some reason this is not adding the gender to the claims. options.Scope.Add("gender"); app.UseAuth0Authentication(options); }
/// <summary> /// Authenticate users using Auth0 /// </summary> /// <param name="app">The <see cref="IAppBuilder"/> passed to the configuration method</param> /// <param name="options">Middleware configuration options</param> /// <returns>The updated <see cref="IAppBuilder"/></returns> public static IAppBuilder UseAuth0Authentication(this IAppBuilder app, Auth0AuthenticationOptions options) { if (app == null) { throw new ArgumentNullException("app"); } if (options == null) { throw new ArgumentNullException("options"); } app.Use(typeof(Auth0AuthenticationMiddleware), app, options); return(app); }
public void Configuration(IAppBuilder app) { 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); // Configure Auth0 authentication var options = new Auth0AuthenticationOptions { ClientId = System.Configuration.ConfigurationManager.AppSettings["auth0:ClientId"], ClientSecret = System.Configuration.ConfigurationManager.AppSettings["auth0:ClientSecret"], Domain = System.Configuration.ConfigurationManager.AppSettings["auth0:Domain"], RedirectPath = new PathString("/Auth0Account/ExternalLoginCallback"), Provider = new Auth0AuthenticationProvider { OnAuthenticated = context => { // Get the user's country JToken countryObject = context.User["country"]; if (countryObject != null) { string country = countryObject.ToObject <string>(); context.Identity.AddClaim(new Claim("country", country, ClaimValueTypes.String, context.Connection)); } // Get the user's roles var rolesObject = context.User["app_metadata"]["roles"]; if (rolesObject != null) { string[] roles = rolesObject.ToObject <string[]>(); foreach (var role in roles) { context.Identity.AddClaim(new Claim(ClaimTypes.Role, role, ClaimValueTypes.String, context.Connection)); } } return(Task.FromResult(0)); } } }; app.UseAuth0Authentication(options); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters string auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; string auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; string auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Enable Kentor Cookie Saver middleware app.UseKentorOwinCookieSaver(); // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); // Configure Auth0 authentication var options = new Auth0AuthenticationOptions() { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, // Save the tokens to claims SaveIdToken = true, SaveAccessToken = true, SaveRefreshToken = true // If you want to request an access_token to pass to an API, then uncomment the code below // and be sure to pass your own API Identifier // Provider = new Auth0AuthenticationProvider // { // OnApplyRedirect = context => // { // context.RedirectUri += "&audience=" + WebUtility.UrlEncode("YOUR_API_IDENTIFIER"); // context.Response.Redirect(context.RedirectUri); // } // } }; options.Scope.Add("offline_access"); // Request a refresh_token app.UseAuth0Authentication(options); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters string auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; string auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; string auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Enable Kentor Cookie Saver middleware app.UseKentorOwinCookieSaver(); // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); // Configure Auth0 authentication var options = new Auth0AuthenticationOptions() { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, SaveIdToken = true, // Scope = { "openid", "profile" }, // If you want to request an access_token to pass to an API, then replace the audience below to // pass your API Identifier instead of the /userinfo endpoint Provider = new Auth0AuthenticationProvider() { OnApplyRedirect = context => { string userInfoAudience = $"https://{auth0Domain}/userinfo"; // string userInfoAudience = "http://localhost/lobbyapi"; string redirectUri = context.RedirectUri + "&audience=" + WebUtility.UrlEncode(userInfoAudience); context.Response.Redirect(redirectUri); } } }; app.UseAuth0Authentication(options); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters string auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; string auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; string auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Enable Kentor Cookie Saver middleware app.UseKentorOwinCookieSaver(); // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); var options = new Auth0AuthenticationOptions() { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, // Save the tokens to claims SaveIdToken = true, SaveAccessToken = true, SaveRefreshToken = true, // If you want to request an access_token to pass to an API, then replace the audience below to // pass your API Identifier instead of the /userinfo endpoint Provider = new Auth0AuthenticationProvider() { OnApplyRedirect = context => { string userInfoAudience = $"https://{auth0Domain}/userinfo"; string redirectUri = context.RedirectUri + "&audience=" + WebUtility.UrlEncode(userInfoAudience); context.Response.Redirect(redirectUri); }, OnAuthenticated = context => { // Get the user's roles var rolesObject = context.User["https://schemas.adafast.com/roles"]; if (rolesObject != null) { string[] roles = rolesObject.ToObject <string[]>(); foreach (var role in roles) { context.Identity.AddClaim(new Claim(ClaimTypes.Role, role, ClaimValueTypes.String, context.Connection)); } } return(Task.FromResult(0)); } } }; options.Scope.Add("email"); // Request user's email address as well app.UseAuth0Authentication(options); app.MapSignalR(); }
public void Configuration(IAppBuilder app) { // Configure Auth0 parameters string auth0Domain = ConfigurationManager.AppSettings["auth0:Domain"]; string auth0ClientId = ConfigurationManager.AppSettings["auth0:ClientId"]; string auth0ClientSecret = ConfigurationManager.AppSettings["auth0:ClientSecret"]; // Set Cookies as default authentication type app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = CookieAuthenticationDefaults.AuthenticationType, LoginPath = new PathString("/Account/Login") }); // Configure Auth0 authentication var provider = new Auth0AuthenticationProvider() { //// When logging out //OnApplyLogout = context => //{ // if (System.Configuration.ConfigurationManager.AppSettings["ForceHttps"] == "true" && // context.LogoutUri.Contains("&returnTo=http%3A%2F%2F")) // { // context.LogoutUri = context.LogoutUri.Replace("&returnTo=http%3A%2F%2F", // "&returnTo=https%3A%2F%2F"); // } // context.Response.Redirect(context.LogoutUri); //}, //// When redirecting to /authorize //OnApplyRedirect = context => //{ // if (System.Configuration.ConfigurationManager.AppSettings["ForceHttps"] == "true" && // context.RedirectUri.Contains("&redirect_uri=http%3A%2F%2F")) // { // context.RedirectUri = context.RedirectUri.Replace("&redirect_uri=http%3A%2F%2F", // "&redirect_uri=https%3A%2F%2F"); // } // context.Response.Redirect(context.RedirectUri); //}, //// When doing the code exchange //OnCustomizeTokenExchangeRedirectUri = (context) => //{ // var redirectUri = context.RedirectUri; // if (System.Configuration.ConfigurationManager.AppSettings["ForceHttps"] == "true" // && redirectUri.StartsWith("http://")) // { // context.RedirectUri = redirectUri.Replace("http://", "https://"); // } //} }; var options = new Auth0AuthenticationOptions() { Domain = auth0Domain, ClientId = auth0ClientId, ClientSecret = auth0ClientSecret, ErrorRedirectPath = new PathString("/Account/LoginError"), Provider = provider }; app.UseAuth0Authentication(options); }