Я использую этот шаблон: https://github.com/jasontaylordev/CleanArchitecture.
Он использует настройки по умолчанию (Код с PKCE):
services.AddIdentityServer()
.AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
Я открыл Почтальон - > Вкладка авторизации -> OAuth 2.0 -> Получить новый токен доступа:
Callback URL: http://localhost:61846/authentication/login-callback
Auth URL: http://localhost:61846/connect/authorize
Access Token URL: http://localhost:61846/connect/token
Code Challenge Method: SHA-256
Client ID: CleanArchitecture.WebUI
Client Secret: N/A
Scope: CleanArchitecture.WebUIAPI openid profile
И я получил следующее сообщение:
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 POST http://localhost:61846/Identity/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fresponse_type%3Dcode%26state%26client_id%3DCleanArchitecture.WebUI%26scope%3DCleanArchitecture.WebUIAPI%2520openid%2520profile%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A61846%252Fauthentication%252Flogin-callback%26code_challenge%3DsJKB_banGTVXC43a5ZqB4bynUtzzasmoxsZ1XJQggG4%26code_challenge_method%3DS256 application/x-www-form-urlencoded 265
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware[10]
No CORS policy found for the specified request.
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint '/Account/Login'
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[3]
Route matched with {page = "/Account/Login", area = "Identity", action = "", controller = ""}. Executing page /Account/Login
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[101]
Executing handler method Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal.LoginModel.OnPostAsync - ModelState is Valid
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 3.1.3 initialized 'ApplicationDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: MigrationsAssembly=CleanArchitecture.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[@__normalizedUserName_0='?' (Size = 256)], CommandType='Text', CommandTimeout='30']
SELECT TOP(1) [a].[Id], [a].[AccessFailedCount], [a].[ConcurrencyStamp], [a].[Email], [a].[EmailConfirmed], [a].[LockoutEnabled], [a].[LockoutEnd], [a].[NormalizedEmail], [a].[NormalizedUserName], [a].[PasswordHash], [a].[PhoneNumber], [a].[PhoneNumberConfirmed], [a].[SecurityStamp], [a].[TwoFactorEnabled], [a].[UserName]
FROM [AspNetUsers] AS [a]
WHERE [a].[NormalizedUserName] = @__normalizedUserName_0
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (1ms) [Parameters=[@__user_Id_0='?' (Size = 450)], CommandType='Text', CommandTimeout='30']
SELECT [a].[Id], [a].[ClaimType], [a].[ClaimValue], [a].[UserId]
FROM [AspNetUserClaims] AS [a]
WHERE [a].[UserId] = @__user_Id_0
dbug: IdentityServer4.Hosting.IdentityServerAuthenticationService[0]
Augmenting SignInContext
dbug: IdentityServer4.Hosting.IdentityServerAuthenticationService[0]
Adding idp claim with value: local
dbug: IdentityServer4.Hosting.IdentityServerAuthenticationService[0]
Adding auth_time claim with value: 1588767352
info: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler[10]
AuthenticationScheme: Identity.Application signed in.
info: Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal.LoginModel[0]
User logged in.
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[102]
Executed handler method OnPostAsync, returned result Microsoft.AspNetCore.Mvc.LocalRedirectResult.
info: Microsoft.AspNetCore.Mvc.Infrastructure.LocalRedirectResultExecutor[1]
Executing LocalRedirectResult, redirecting to /connect/authorize/callback?response_type=code&state&client_id=CleanArchitecture.WebUI&scope=CleanArchitecture.WebUIAPI%20openid%20profile&redirect_uri=http%3A%2F%2Flocalhost%3A61846%2Fauthentication%2Flogin-callback&code_challenge=sJKB_banGTVXC43a5ZqB4bynUtzzasmoxsZ1XJQggG4&code_challenge_method=S256.
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[4]
Executed page /Account/Login in 78.1628ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint '/Account/Login'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 94.3536ms 302
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/connect/authorize/callback?response_type=code&state&client_id=CleanArchitecture.WebUI&scope=CleanArchitecture.WebUIAPI%20openid%20profile&redirect_uri=http%3A%2F%2Flocalhost%3A61846%2Fauthentication%2Flogin-callback&code_challenge=sJKB_banGTVXC43a5ZqB4bynUtzzasmoxsZ1XJQggG4&code_challenge_method=S256
dbug: IdentityServer4.Hosting.EndpointRouter[0]
Request path /connect/authorize/callback matched to endpoint type Authorize
dbug: IdentityServer4.Hosting.EndpointRouter[0]
Endpoint enabled: Authorize, successfully created handler: IdentityServer4.Endpoints.AuthorizeCallbackEndpoint
info: IdentityServer4.Hosting.IdentityServerMiddleware[0]
Invoking IdentityServer endpoint: IdentityServer4.Endpoints.AuthorizeCallbackEndpoint for /connect/authorize/callback
dbug: IdentityServer4.Endpoints.AuthorizeCallbackEndpoint[0]
Start authorize callback request
dbug: IdentityServer4.Endpoints.AuthorizeCallbackEndpoint[0]
No user present in authorize request
dbug: IdentityServer4.Validation.AuthorizeRequestValidator[0]
Start authorize request protocol validation
dbug: IdentityServer4.Stores.ValidatingClientStore[0]
client configuration validation for client CleanArchitecture.WebUI succeeded.
dbug: IdentityServer4.Validation.AuthorizeRequestValidator[0]
Checking for PKCE parameters
dbug: IdentityServer4.Validation.AuthorizeRequestValidator[0]
Calling into custom validator: IdentityServer4.Validation.DefaultCustomAuthorizeRequestValidator
dbug: IdentityServer4.Endpoints.AuthorizeCallbackEndpoint[0]
ValidatedAuthorizeRequest
{
"ClientId": "CleanArchitecture.WebUI",
"ClientName": "CleanArchitecture.WebUI",
"RedirectUri": "http://localhost:61846/authentication/login-callback",
"AllowedRedirectUris": [
"/authentication/login-callback"
],
"SubjectId": "anonymous",
"ResponseType": "code",
"ResponseMode": "query",
"GrantType": "authorization_code",
"RequestedScopes": "CleanArchitecture.WebUIAPI openid profile",
"Raw": {
"response_type": "code",
"state": "",
"client_id": "CleanArchitecture.WebUI",
"scope": "CleanArchitecture.WebUIAPI openid profile",
"redirect_uri": "http://localhost:61846/authentication/login-callback",
"code_challenge": "sJKB_banGTVXC43a5ZqB4bynUtzzasmoxsZ1XJQggG4",
"code_challenge_method": "S256"
}
}
info: IdentityServer4.ResponseHandling.AuthorizeInteractionResponseGenerator[0]
Showing login: User is not authenticated
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 37.5162ms 302
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/Identity/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fresponse_type%3Dcode%26state%26client_id%3DCleanArchitecture.WebUI%26scope%3DCleanArchitecture.WebUIAPI%2520openid%2520profile%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A61846%252Fauthentication%252Flogin-callback%26code_challenge%3DsJKB_banGTVXC43a5ZqB4bynUtzzasmoxsZ1XJQggG4%26code_challenge_method%3DS256
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint '/Account/Login'
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[3]
Route matched with {page = "/Account/Login", area = "Identity", action = "", controller = ""}. Executing page /Account/Login
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[101]
Executing handler method Microsoft.AspNetCore.Identity.UI.V4.Pages.Account.Internal.LoginModel.OnGetAsync - ModelState is Valid
info: Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationHandler[11]
AuthenticationScheme: Identity.External signed out.
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[102]
Executed handler method OnGetAsync, returned result .
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[103]
Executing an implicit handler method - ModelState is Valid
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[104]
Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
info: Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker[4]
Executed page /Account/Login in 17.1263ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint '/Account/Login'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 28.8973ms 200 text/html; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 19721.5878ms 304
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/styles.css
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/vendor.js
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/runtime.js
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/polyfills.js
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/main.js
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 34.705ms 304
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 2037.5013ms 304
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 2040.3326ms 304
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 2043.9964ms 304
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 2048.8137ms 304
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/_configuration/CleanArchitecture.WebUI
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'CleanArchitecture.WebUI.Controllers.OidcConfigurationController.GetClientRequestParameters (CleanArchitecture.WebUI)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = "GetClientRequestParameters", controller = "OidcConfiguration", page = "", area = ""}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult GetClientRequestParameters(System.String) on controller CleanArchitecture.WebUI.Controllers.OidcConfigurationController (CleanArchitecture.WebUI).
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
Executing ObjectResult, writing value of type 'System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
Executed action CleanArchitecture.WebUI.Controllers.OidcConfigurationController.GetClientRequestParameters (CleanArchitecture.WebUI) in 17.5631ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'CleanArchitecture.WebUI.Controllers.OidcConfigurationController.GetClientRequestParameters (CleanArchitecture.WebUI)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 37.9369ms 200 application/json; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/_configuration/CleanArchitecture.WebUI
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[0]
Executing endpoint 'CleanArchitecture.WebUI.Controllers.OidcConfigurationController.GetClientRequestParameters (CleanArchitecture.WebUI)'
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[3]
Route matched with {action = "GetClientRequestParameters", controller = "OidcConfiguration", page = "", area = ""}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult GetClientRequestParameters(System.String) on controller CleanArchitecture.WebUI.Controllers.OidcConfigurationController (CleanArchitecture.WebUI).
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/sockjs-node/info?t=1588767356368
info: Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor[1]
Executing ObjectResult, writing value of type 'System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'.
info: Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker[2]
Executed action CleanArchitecture.WebUI.Controllers.OidcConfigurationController.GetClientRequestParameters (CleanArchitecture.WebUI) in 6.4239ms
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
Executed endpoint 'CleanArchitecture.WebUI.Controllers.OidcConfigurationController.GetClientRequestParameters (CleanArchitecture.WebUI)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 19.9405ms 200 application/json; charset=utf-8
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 18.469ms 200 application/json; charset=UTF-8
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/favicon.ico
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 GET http://localhost:61846/sockjs-node/997/brsoeizx/websocket
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware[10]
No CORS policy found for the specified request.
info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
Sending file. Request path: '/favicon.ico'. Physical path: 'C:\Users\Admin\Desktop\BackEnd Stuff\CleanArchitecture-master\src\WebUI\wwwroot\favicon.ico'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
Request finished in 34.0225ms 200 image/x-icon
info: Microsoft.AspNetCore.Hosting.Diagnostics[1]
Request starting HTTP/1.1 POST http://localhost:61846/sockjs-node/997/hugz4yrs/xhr_streaming?t=1588767357060 0
info: Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware[10]
No CORS policy found for the specified request.
Как мне пройти аутентификацию вместо этого сообщения Showing login: User is not authenticated
? Каково нормальное поведение?