@@ -347,61 +347,67 @@ public void ConfigureServices(IServiceCollection services)
347
347
// Note: use the generic overload if you need
348
348
// to replace the default OpenIddict entities.
349
349
services . AddOpenIddict ( )
350
- . AddCore ( options =>
350
+ . AddCore ( coreBuilder =>
351
351
{
352
- options . UseEntityFrameworkCore ( )
353
- . UseDbContext < SecurityDbContext > ( ) ;
354
- } ) . AddServer ( options =>
352
+ coreBuilder . UseEntityFrameworkCore ( efBuilder =>
353
+ {
354
+ efBuilder . UseDbContext < SecurityDbContext > ( ) ;
355
+ } ) ;
356
+ } )
357
+ . AddServer ( serverBuilder =>
355
358
{
356
359
// Register the ASP.NET Core MVC binder used by OpenIddict.
357
360
// Note: if you don't call this method, you won't be able to
358
361
// bind OpenIdConnectRequest or OpenIdConnectResponse parameters.
359
- var builder = options . UseAspNetCore ( ) .
360
- EnableTokenEndpointPassthrough ( ) .
361
- EnableAuthorizationEndpointPassthrough ( ) ;
362
+ serverBuilder . UseAspNetCore ( aspNetBuilder =>
363
+ {
364
+ aspNetBuilder . EnableTokenEndpointPassthrough ( ) ;
365
+ aspNetBuilder . EnableAuthorizationEndpointPassthrough ( ) ;
366
+
367
+ // When request caching is enabled, authorization and logout requests
368
+ // are stored in the distributed cache by OpenIddict and the user agent
369
+ // is redirected to the same page with a single parameter (request_id).
370
+ // This allows flowing large OpenID Connect requests even when using
371
+ // an external authentication provider like Google, Facebook or Twitter.
372
+ aspNetBuilder . EnableAuthorizationRequestCaching ( ) ;
373
+ aspNetBuilder . EnableLogoutRequestCaching ( ) ;
374
+
375
+ // During development or when you explicitly run the platform in production mode without https,
376
+ // need to disable the HTTPS requirement.
377
+ if ( WebHostEnvironment . IsDevelopment ( ) || platformOptions . AllowInsecureHttp || ! Configuration . IsHttpsServerUrlSet ( ) )
378
+ {
379
+ aspNetBuilder . DisableTransportSecurityRequirement ( ) ;
380
+ }
381
+ } ) ;
362
382
363
383
// Enable the authorization, logout, token and userinfo endpoints.
364
- options . SetTokenEndpointUris ( "connect/token" ) ;
365
- options . SetUserinfoEndpointUris ( "api/security/userinfo" ) ;
384
+ serverBuilder . SetTokenEndpointUris ( "connect/token" ) ;
385
+ serverBuilder . SetUserinfoEndpointUris ( "api/security/userinfo" ) ;
366
386
367
387
// Note: the Mvc.Client sample only uses the code flow and the password flow, but you
368
388
// can enable the other flows if you need to support implicit or client credentials.
369
- options . AllowPasswordFlow ( )
370
- . AllowRefreshTokenFlow ( )
371
- . AllowClientCredentialsFlow ( )
372
- . AllowCustomFlow ( PlatformConstants . Security . GrantTypes . Impersonate )
373
- . AllowCustomFlow ( PlatformConstants . Security . GrantTypes . ExternalSignIn ) ;
389
+ serverBuilder . AllowPasswordFlow ( ) ;
390
+ serverBuilder . AllowRefreshTokenFlow ( ) ;
391
+ serverBuilder . AllowClientCredentialsFlow ( ) ;
392
+ serverBuilder . AllowCustomFlow ( PlatformConstants . Security . GrantTypes . Impersonate ) ;
393
+ serverBuilder . AllowCustomFlow ( PlatformConstants . Security . GrantTypes . ExternalSignIn ) ;
374
394
375
- options . SetRefreshTokenLifetime ( authorizationOptions ? . RefreshTokenLifeTime ) ;
376
- options . SetAccessTokenLifetime ( authorizationOptions ? . AccessTokenLifeTime ) ;
395
+ serverBuilder . SetRefreshTokenLifetime ( authorizationOptions ? . RefreshTokenLifeTime ) ;
396
+ serverBuilder . SetAccessTokenLifetime ( authorizationOptions ? . AccessTokenLifeTime ) ;
377
397
378
- options . AcceptAnonymousClients ( ) ;
398
+ serverBuilder . AcceptAnonymousClients ( ) ;
379
399
380
400
// Configure Openiddict to issues new refresh token for each token refresh request.
381
- // Enabled by default, to disable use options .DisableRollingRefreshTokens()
401
+ // Enabled by default, to disable use serverBuilder .DisableRollingRefreshTokens()
382
402
383
403
// Make the "client_id" parameter mandatory when sending a token request.
384
404
//options.RequireClientIdentification()
385
405
386
- // When request caching is enabled, authorization and logout requests
387
- // are stored in the distributed cache by OpenIddict and the user agent
388
- // is redirected to the same page with a single parameter (request_id).
389
- // This allows flowing large OpenID Connect requests even when using
390
- // an external authentication provider like Google, Facebook or Twitter.
391
- builder . EnableAuthorizationRequestCaching ( ) ;
392
- builder . EnableLogoutRequestCaching ( ) ;
393
-
394
- options . DisableScopeValidation ( ) ;
395
-
396
- // During development or when you explicitly run the platform in production mode without https, need to disable the HTTPS requirement.
397
- if ( WebHostEnvironment . IsDevelopment ( ) || platformOptions . AllowInsecureHttp || ! Configuration . IsHttpsServerUrlSet ( ) )
398
- {
399
- builder . DisableTransportSecurityRequirement ( ) ;
400
- }
406
+ serverBuilder . DisableScopeValidation ( ) ;
401
407
402
408
// Note: to use JWT access tokens instead of the default
403
409
// encrypted format, the following lines are required:
404
- options . DisableAccessTokenEncryption ( ) ;
410
+ serverBuilder . DisableAccessTokenEncryption ( ) ;
405
411
406
412
X509Certificate2 privateKey ;
407
413
if ( RuntimeInformation . IsOSPlatform ( OSPlatform . OSX ) )
@@ -416,8 +422,9 @@ public void ConfigureServices(IServiceCollection services)
416
422
{
417
423
privateKey = new X509Certificate2 ( ServerCertificate . PrivateKeyCertBytes , ServerCertificate . PrivateKeyCertPassword , X509KeyStorageFlags . MachineKeySet | X509KeyStorageFlags . EphemeralKeySet ) ;
418
424
}
419
- options . AddSigningCertificate ( privateKey ) ;
420
- options . AddEncryptionCertificate ( privateKey ) ;
425
+
426
+ serverBuilder . AddSigningCertificate ( privateKey ) ;
427
+ serverBuilder . AddEncryptionCertificate ( privateKey ) ;
421
428
} ) ;
422
429
423
430
services . Configure < IdentityOptions > ( Configuration . GetSection ( "IdentityOptions" ) ) ;
0 commit comments