From 8263d95312002895ab81ae837d85427e5684a788 Mon Sep 17 00:00:00 2001 From: OpenIddict Bot <32257313+openiddict-bot@users.noreply.github.com> Date: Wed, 13 Jan 2021 04:53:51 +0000 Subject: [PATCH] Update the documentation pages --- guide/getting-started.html | 64 +++++++++++++++++++------------------- manifest.json | 2 +- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/guide/getting-started.html b/guide/getting-started.html index eff565f..7294b71 100644 --- a/guide/getting-started.html +++ b/guide/getting-started.html @@ -103,9 +103,9 @@ Here's an example for the client credentials grant, used in machine-to-machi .AddCore(options => { // 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() - .UseDbContext<ApplicationDbContext>(); + .UseDbContext<ApplicationDbContext>(); }) // 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() .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() .EnableTokenEndpointPassthrough(); }) @@ -173,7 +173,7 @@ Here's an example for the client credentials grant, used in machine-to-machi }); -

-> [!NOTE]

+

-> [!WARNING]

Important: if you change the default entity primary key (e.g. to int or Guid instead of string), make sure you use the options.ReplaceDefaultEntities<TKey>() core extension accepting a TKey generic argument and use the generic options.UseOpenIddict<TKey>() overload to configure Entity Framework Core to use the specified key type:

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:

public class AuthorizationController : Controller
 {
-    private readonly OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> _applicationManager;
+    private readonly IOpenIddictApplicationManager_applicationManager;
 
-    public AuthorizationController(OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication> applicationManager)
+    public AuthorizationController(IOpenIddictApplicationManager applicationManager)
         => _applicationManager = applicationManager;
 
     [HttpPost("~/connect/token"), Produces("application/json")]
     public async Task<IActionResult> Exchange()
     {
         var request = HttpContext.GetOpenIddictServerRequest();
-        if (request.IsClientCredentialsGrantType())
+        if (!request.IsClientCredentialsGrantType())
         {
-            // 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);
+            throw new NotImplementedException("The specified grant type is not implemented.");
         }
 
-        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);
     }
 }
 
@@ -254,7 +254,7 @@ Here's an example for the client credentials grant:

var context = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>(); await context.Database.EnsureCreatedAsync(); - var manager = scope.ServiceProvider.GetRequiredService<OpenIddictApplicationManager<OpenIddictEntityFrameworkCoreApplication>>(); + var manager = scope.ServiceProvider.GetRequiredService<IOpenIddictApplicationManager>(); if (await manager.FindByClientIdAsync("console") is null) { diff --git a/manifest.json b/manifest.json index e4e6fdd..4219688 100644 --- a/manifest.json +++ b/manifest.json @@ -45,7 +45,7 @@ "output": { ".html": { "relative_path": "guide/getting-started.html", - "hash": "B+LUpBca5+kh6NFTvwCenQ==" + "hash": "EubGbQd6qMqQ/UD3oj2WIw==" } }, "is_incremental": false,