Skip to content

Commit

Permalink
Update the C# snippets to use collection expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchalet committed Apr 8, 2024
1 parent 786116d commit 7ba3ae9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
13 changes: 5 additions & 8 deletions configuration/authorization-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,19 @@ switch (await _applicationManager.GetConsentTypeAsync(application))
{
// If the "profile" scope was granted, allow the "name" claim to be
// added to the access and identity tokens derived from the principal.
Claims.Name when claim.Subject.HasScope(Scopes.Profile) => new[]
{
Claims.Name when claim.Subject.HasScope(Scopes.Profile) =>
[
OpenIddictConstants.Destinations.AccessToken,
OpenIddictConstants.Destinations.IdentityToken
},
],

// Never add the "secret_value" claim to access or identity tokens.
// In this case, it will only be added to authorization codes,
// refresh tokens and user/device codes, that are always encrypted.
"secret_value" => Array.Empty<string>(),
"secret_value" => [],

// Otherwise, add the claim to the access tokens only.
_ => new[]
{
OpenIddictConstants.Destinations.AccessToken
}
_ => [OpenIddictConstants.Destinations.AccessToken]
});

return SignIn(new ClaimsPrincipal(identity), OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
Expand Down
13 changes: 5 additions & 8 deletions configuration/claim-destinations.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,19 @@ principal.SetDestinations(static claim => claim.Type switch
{
// If the "profile" scope was granted, allow the "name" claim to be
// added to the access and identity tokens derived from the principal.
Claims.Name when claim.Subject.HasScope(Scopes.Profile) => new[]
{
Claims.Name when claim.Subject.HasScope(Scopes.Profile) =>
[
OpenIddictConstants.Destinations.AccessToken,
OpenIddictConstants.Destinations.IdentityToken
},
],

// Never add the "secret_value" claim to access or identity tokens.
// In this case, it will only be added to authorization codes,
// refresh tokens and user/device codes, that are always encrypted.
"secret_value" => Array.Empty<string>(),
"secret_value" => [],

// Otherwise, add the claim to the access tokens only.
_ => new[]
{
OpenIddictConstants.Destinations.AccessToken
}
_ => [OpenIddictConstants.Destinations.AccessToken]
});

return SignIn(principal, OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
Expand Down
2 changes: 1 addition & 1 deletion guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ app.MapGet("/authorize", async (HttpContext context) =>
var principal = (await context.AuthenticateAsync(SteamAuthenticationDefaults.AuthenticationScheme))?.Principal;
if (principal is null)
{
return Results.Challenge(properties: null, new[] { SteamAuthenticationDefaults.AuthenticationScheme });
return Results.Challenge(properties: null, [SteamAuthenticationDefaults.AuthenticationScheme]);
}

var identifier = principal.FindFirst(ClaimTypes.NameIdentifier)!.Value;
Expand Down
4 changes: 2 additions & 2 deletions guides/migration/30-to-40.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ identity.SetDestinations(static claim => claim.Type switch
// Allow the "name" claim to be stored in both the access and identity tokens
// when the "profile" scope was granted (by calling principal.SetScopes(...)).
Claims.Name when claim.Subject.HasScope(Scopes.Profile)
=> new[] { Destinations.AccessToken, Destinations.IdentityToken },
=> [Destinations.AccessToken, Destinations.IdentityToken],

// Otherwise, only store the claim in the access tokens.
_ => new[] { Destinations.AccessToken }
_ => [Destinations.AccessToken]
});
```

Expand Down
12 changes: 6 additions & 6 deletions integrations/mongodb.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ initialize the database and create the indexes used by the OpenIddict entities:

var applications = database.GetCollection<OpenIddictMongoDbApplication>(options.ApplicationsCollectionName);

await applications.Indexes.CreateManyAsync(new[]
{
await applications.Indexes.CreateManyAsync(
[
new CreateIndexModel<OpenIddictMongoDbApplication>(
Builders<OpenIddictMongoDbApplication>.IndexKeys.Ascending(application => application.ClientId),
new CreateIndexOptions
Expand All @@ -82,7 +82,7 @@ initialize the database and create the indexes used by the OpenIddict entities:
{
Background = true
})
});
]);

var authorizations = database.GetCollection<OpenIddictMongoDbAuthorization>(options.AuthorizationsCollectionName);

Expand Down Expand Up @@ -110,8 +110,8 @@ initialize the database and create the indexes used by the OpenIddict entities:

var tokens = database.GetCollection<OpenIddictMongoDbToken>(options.TokensCollectionName);

await tokens.Indexes.CreateManyAsync(new[]
{
await tokens.Indexes.CreateManyAsync(
[
new CreateIndexModel<OpenIddictMongoDbToken>(
Builders<OpenIddictMongoDbToken>.IndexKeys.Ascending(token => token.ReferenceId),
new CreateIndexOptions<OpenIddictMongoDbToken>
Expand Down Expand Up @@ -140,7 +140,7 @@ initialize the database and create the indexes used by the OpenIddict entities:
{
Background = true
})
});
]);
```

## Advanced configuration
Expand Down

0 comments on commit 7ba3ae9

Please sign in to comment.