Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DonkeyKongJr/7140f2bc40d07b47cfa095c8d451ea51 to your computer and use it in GitHub Desktop.
Save DonkeyKongJr/7140f2bc40d07b47cfa095c8d451ea51 to your computer and use it in GitHub Desktop.
public void ConfigureServices(IServiceCollection services)
{
   // Add authentication services
   services.AddAuthentication(options => {
       options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme;
       options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
       options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme;
   })
   .AddCookie()
   .AddOpenIdConnect("Auth0", options => {
       // Set the authority to your Auth0 domain
       options.Authority = $"https://{Configuration["Auth0:Domain"]}";
       // Configure the Auth0 Client ID and Client Secret
       options.ClientId = Configuration["Auth0:ClientId"];
       options.ClientSecret = Configuration["Auth0:ClientSecret"];
       // Set response type to code
       options.ResponseType = "code";
       // Configure the scope
       options.Scope.Clear();
       options.Scope.Add("openid");
       // Set the callback path, so Auth0 will call back to http://localhost:3000/callback
       // Also ensure that you have added the URL as an Allowed Callback URL in your Auth0 dashboard
       options.CallbackPath = new PathString("/callback");
       // Configure the Claims Issuer to be Auth0
       options.ClaimsIssuer = "Auth0";
   });
   // Add framework services.
   services.AddMvc();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment