-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
using Duende.IdentityServer; | ||
using IdentityServer.Data; | ||
using IdentityServer.Models; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Microsoft.IdentityModel.Logging; | ||
using Serilog; | ||
|
||
namespace IdentityServer; | ||
|
||
internal static class HostingExtensions | ||
{ | ||
public static WebApplication ConfigureServices(this WebApplicationBuilder builder) | ||
{ | ||
JsonWebTokenHandler.DefaultInboundClaimTypeMap.Clear(); | ||
|
||
builder.Services.AddRazorPages(); | ||
|
||
builder.Services.AddDbContext<ApplicationDbContext>(options => | ||
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); | ||
|
||
builder.Services.AddIdentity<ApplicationUser, IdentityRole>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>() | ||
.AddDefaultTokenProviders(); | ||
|
||
builder.Services | ||
.AddIdentityServer(options => | ||
{ | ||
options.Events.RaiseErrorEvents = true; | ||
options.Events.RaiseInformationEvents = true; | ||
options.Events.RaiseFailureEvents = true; | ||
options.Events.RaiseSuccessEvents = true; | ||
|
||
// see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/ | ||
options.EmitStaticAudienceClaim = true; | ||
}) | ||
.AddInMemoryIdentityResources(Config.IdentityResources) | ||
.AddInMemoryApiScopes(Config.ApiScopes) | ||
.AddInMemoryClients(Config.Clients) | ||
using Duende.IdentityServer; | ||
using IdentityServer.Data; | ||
using IdentityServer.Models; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.IdentityModel.JsonWebTokens; | ||
using Microsoft.IdentityModel.Logging; | ||
using Serilog; | ||
|
||
namespace IdentityServer; | ||
|
||
internal static class HostingExtensions | ||
{ | ||
public static WebApplication ConfigureServices(this WebApplicationBuilder builder) | ||
{ | ||
JsonWebTokenHandler.DefaultInboundClaimTypeMap.Clear(); | ||
|
||
builder.Services.AddRazorPages(); | ||
|
||
builder.Services.AddDbContext<ApplicationDbContext>(options => | ||
options.UseSqlite(builder.Configuration.GetConnectionString("DefaultConnection"))); | ||
|
||
builder.Services.AddIdentity<ApplicationUser, IdentityRole>() | ||
.AddEntityFrameworkStores<ApplicationDbContext>() | ||
.AddDefaultTokenProviders(); | ||
|
||
builder.Services | ||
.AddIdentityServer(options => | ||
{ | ||
options.Events.RaiseErrorEvents = true; | ||
options.Events.RaiseInformationEvents = true; | ||
options.Events.RaiseFailureEvents = true; | ||
options.Events.RaiseSuccessEvents = true; | ||
|
||
// see https://docs.duendesoftware.com/identityserver/v6/fundamentals/resources/ | ||
options.EmitStaticAudienceClaim = true; | ||
}) | ||
.AddInMemoryIdentityResources(Config.IdentityResources) | ||
.AddInMemoryApiScopes(Config.ApiScopes) | ||
.AddInMemoryClients(Config.Clients) | ||
.AddAspNetIdentity<ApplicationUser>(); | ||
|
||
builder.Services.AddAuthentication() | ||
.AddGoogle(options => | ||
{ | ||
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; | ||
|
||
// register your IdentityServer with Google at https://console.developers.google.com | ||
// enable the Google+ API | ||
// set the redirect URI to https://localhost:5001/signin-google | ||
options.ClientId = "copy client ID from Google here"; | ||
options.ClientSecret = "copy client secret from Google here"; | ||
}); | ||
|
||
return builder.Build(); | ||
builder.Services.AddAuthentication() | ||
.AddGoogle(options => | ||
{ | ||
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme; | ||
|
||
// register your IdentityServer with Google at https://console.developers.google.com | ||
// enable the Google+ API | ||
// set the redirect URI to https://localhost:5001/signin-google | ||
options.ClientId = "copy client ID from Google here"; | ||
options.ClientSecret = "copy client secret from Google here"; | ||
}); | ||
|
||
return builder.Build(); | ||
} | ||
|
||
public static WebApplication ConfigurePipeline(this WebApplication app) | ||
{ | ||
public static WebApplication ConfigurePipeline(this WebApplication app) | ||
{ | ||
IdentityModelEventSource.ShowPII = true; | ||
|
||
app.UseSerilogRequestLogging(); | ||
|
||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseStaticFiles(); | ||
app.UseRouting(); | ||
app.UseIdentityServer(); | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
app.UseStaticFiles(); | ||
app.UseRouting(); | ||
app.UseIdentityServer(); | ||
app.UseAuthorization(); | ||
|
||
app.MapRazorPages() | ||
.RequireAuthorization(); | ||
|
||
return app; | ||
} | ||
app.MapRazorPages() | ||
.RequireAuthorization(); | ||
|
||
return app; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters