mirror of
https://gitee.com/dcren/openiddict-documentation.git
synced 2025-07-15 05:13:19 +08:00
Update the documentation pages
This commit is contained in:
parent
c24ded39ce
commit
8263d95312
@ -103,9 +103,9 @@ Here's an example for the client credentials grant, used in machine-to-machi
|
|||||||
.AddCore(options =>
|
.AddCore(options =>
|
||||||
{
|
{
|
||||||
// Configure OpenIddict to use the Entity Framework Core stores and models.
|
// Configure OpenIddict to use the Entity Framework Core stores and models.
|
||||||
// Note: call ReplaceDefaultEntities() to replace the default OpenIddict entities.
|
// Note: call ReplaceDefaultEntities() to replace the default entities.
|
||||||
options.UseEntityFrameworkCore()
|
options.UseEntityFrameworkCore()
|
||||||
.UseDbContext<ApplicationDbContext>();
|
.UseDbContext<ApplicationDbContext>();
|
||||||
})
|
})
|
||||||
|
|
||||||
// Register the OpenIddict server components.
|
// Register the OpenIddict server components.
|
||||||
@ -121,7 +121,7 @@ Here's an example for the client credentials grant, used in machine-to-machi
|
|||||||
options.AddDevelopmentEncryptionCertificate()
|
options.AddDevelopmentEncryptionCertificate()
|
||||||
.AddDevelopmentSigningCertificate();
|
.AddDevelopmentSigningCertificate();
|
||||||
|
|
||||||
// Register the ASP.NET Core host and configure the ASP.NET Core-specific options.
|
// Register the ASP.NET Core host and configure the ASP.NET Core options.
|
||||||
options.UseAspNetCore()
|
options.UseAspNetCore()
|
||||||
.EnableTokenEndpointPassthrough();
|
.EnableTokenEndpointPassthrough();
|
||||||
})
|
})
|
||||||
@ -173,7 +173,7 @@ Here's an example for the client credentials grant, used in machine-to-machi
|
|||||||
});
|
});
|
||||||
</code></pre></li>
|
</code></pre></li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>-> [!NOTE]</p>
|
<p>-> [!WARNING]</p>
|
||||||
<blockquote><p>Important: if you change the default entity primary key (e.g. to <code>int</code> or <code>Guid</code> instead of <code>string</code>), make sure you use the <code>options.ReplaceDefaultEntities<TKey>()</code>
|
<blockquote><p>Important: if you change the default entity primary key (e.g. to <code>int</code> or <code>Guid</code> instead of <code>string</code>), make sure you use the <code>options.ReplaceDefaultEntities<TKey>()</code>
|
||||||
core extension accepting a <code>TKey</code> generic argument and use the generic <code>options.UseOpenIddict<TKey>()</code> overload to configure Entity Framework Core to use the specified key type:</p>
|
core extension accepting a <code>TKey</code> generic argument and use the generic <code>options.UseOpenIddict<TKey>()</code> overload to configure Entity Framework Core to use the specified key type:</p>
|
||||||
<pre><code class="lang-csharp">services.AddOpenIddict()
|
<pre><code class="lang-csharp">services.AddOpenIddict()
|
||||||
@ -199,43 +199,43 @@ Implementing a custom authorization controller is required to allow OpenIddict t
|
|||||||
Here's an example for the client credentials grant:</p>
|
Here's an example for the client credentials grant:</p>
|
||||||
<pre><code class="lang-csharp">public class AuthorizationController : Controller
|
<pre><code class="lang-csharp">public class AuthorizationController : Controller
|
||||||
{
|
{
|
||||||
private readonly OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> _applicationManager;
|
private readonly IOpenIddictApplicationManager_applicationManager;
|
||||||
|
|
||||||
public AuthorizationController(OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> applicationManager)
|
public AuthorizationController(IOpenIddictApplicationManager applicationManager)
|
||||||
=> _applicationManager = applicationManager;
|
=> _applicationManager = applicationManager;
|
||||||
|
|
||||||
[HttpPost("~/connect/token"), Produces("application/json")]
|
[HttpPost("~/connect/token"), Produces("application/json")]
|
||||||
public async Task<IActionResult> Exchange()
|
public async Task<IActionResult> Exchange()
|
||||||
{
|
{
|
||||||
var request = HttpContext.GetOpenIddictServerRequest();
|
var request = HttpContext.GetOpenIddictServerRequest();
|
||||||
if (request.IsClientCredentialsGrantType())
|
if (!request.IsClientCredentialsGrantType())
|
||||||
{
|
{
|
||||||
// Note: the client credentials are automatically validated by OpenIddict:
|
throw new NotImplementedException("The specified grant type is not implemented.");
|
||||||
// if client_id or client_secret are invalid, this action won't be invoked.
|
|
||||||
|
|
||||||
var application = await _applicationManager.FindByClientIdAsync(request.ClientId);
|
|
||||||
if (application == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("The application details cannot be found in the database.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a new ClaimsIdentity containing the claims that
|
|
||||||
// will be used to create an id_token, a token or a code.
|
|
||||||
var identity = new ClaimsIdentity(
|
|
||||||
TokenValidationParameters.DefaultAuthenticationType,
|
|
||||||
Claims.Name, Claims.Role);
|
|
||||||
|
|
||||||
// Use the client_id as the subject identifier.
|
|
||||||
identity.AddClaim(Claims.Subject, await _applicationManager.GetClientIdAsync(application),
|
|
||||||
Destinations.AccessToken, Destinations.IdentityToken);
|
|
||||||
|
|
||||||
identity.AddClaim(Claims.Name, await _applicationManager.GetDisplayNameAsync(application),
|
|
||||||
Destinations.AccessToken, Destinations.IdentityToken);
|
|
||||||
|
|
||||||
return SignIn(new ClaimsPrincipal(identity), OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotImplementedException("The specified grant type is not implemented.");
|
// Note: the client credentials are automatically validated by OpenIddict:
|
||||||
|
// if client_id or client_secret are invalid, this action won't be invoked.
|
||||||
|
|
||||||
|
var application = await _applicationManager.FindByClientIdAsync(request.ClientId);
|
||||||
|
if (application == null)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("The application details cannot be found in the database.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new ClaimsIdentity containing the claims that
|
||||||
|
// will be used to create an id_token, a token or a code.
|
||||||
|
var identity = new ClaimsIdentity(
|
||||||
|
TokenValidationParameters.DefaultAuthenticationType,
|
||||||
|
Claims.Name, Claims.Role);
|
||||||
|
|
||||||
|
// Use the client_id as the subject identifier.
|
||||||
|
identity.AddClaim(Claims.Subject, await _applicationManager.GetClientIdAsync(application),
|
||||||
|
Destinations.AccessToken, Destinations.IdentityToken);
|
||||||
|
|
||||||
|
identity.AddClaim(Claims.Name, await _applicationManager.GetDisplayNameAsync(application),
|
||||||
|
Destinations.AccessToken, Destinations.IdentityToken);
|
||||||
|
|
||||||
|
return SignIn(new ClaimsPrincipal(identity), OpenIddictServerAspNetCoreDefaults.AuthenticationScheme);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</code></pre></li>
|
</code></pre></li>
|
||||||
@ -254,7 +254,7 @@ Here's an example for the client credentials grant:</p>
|
|||||||
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
|
||||||
await context.Database.EnsureCreatedAsync();
|
await context.Database.EnsureCreatedAsync();
|
||||||
|
|
||||||
var manager = scope.ServiceProvider.GetRequiredService<OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication>>();
|
var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>();
|
||||||
|
|
||||||
if (await manager.FindByClientIdAsync("console") is null)
|
if (await manager.FindByClientIdAsync("console") is null)
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
"output": {
|
"output": {
|
||||||
".html": {
|
".html": {
|
||||||
"relative_path": "guide/getting-started.html",
|
"relative_path": "guide/getting-started.html",
|
||||||
"hash": "B+LUpBca5+kh6NFTvwCenQ=="
|
"hash": "EubGbQd6qMqQ/UD3oj2WIw=="
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"is_incremental": false,
|
"is_incremental": false,
|
||||||
|
Loading…
Reference in New Issue
Block a user