Search code examples
angularidentityserver4

Angular 2 and Identity server4 server_error


I am testing Identity server 4 with Angular 2 client with implicit flow. Here is the sample codes I used.

  1. Identity server 4 QuickStarts 8 for Identity Server sample

  2. Client Angular project A simple demonstration of using IdentityModel/oidc-client with angular 2

When I click the button, the client app redirect to Identity Server for login. However, a server error was displayed when the login info is accepted. Here is the trace from output window:

Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/.well-known/openid-configuration  
IdentityServer4.Hosting.IdentityServerMiddleware:Information: Invoking IdentityServer endpoint: 
IdentityServer4.Endpoints.DiscoveryEndpoint for /.well-known/openid-configuration
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 412.3457ms 200 application/json
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/connect/authorize?client_id=js.tokenmanager&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauth.html&respon
se_type=id_token%20token&scope=openid%20profile%20email%20api1&state=a2cb0e10e47141abbb208b0cc8c3123f&nonce=4dbb74883e34404d803
ef29f61e8bebb  
IdentityServer4.Hosting.IdentityServerMiddleware:Information: Invoking IdentityServer endpoint: 
IdentityServer4.Endpoints.AuthorizeEndpoint for /connect/authorize
IdentityServer4.Endpoints.AuthorizeEndpoint:Information:  

    ValidatedAuthorizeRequest
     {
     "ClientId": "js.tokenmanager",
     "ClientName": "js.tokenmanager",
     "RedirectUri": "http://localhost:4200/auth.html",
     "AllowedRedirectUris": [
      "http://localhost:4200/auth.html"
     ],
    "SubjectId": "anonymous",
    "ResponseType": "id_token token",
     "ResponseMode": "fragment",
     "GrantType": "implicit",
     "RequestedScopes": "openid profile email api1",
    "State": "a2cb0e10e47141abbb208b0cc8c3123f",
    "Nonce": "4dbb74883e34404d803ef29f61e8bebb",
    "Raw": {
     "client_id": "js.tokenmanager",
     "redirect_uri": "http://localhost:4200/auth.html",
     "response_type": "id_token token",
     "scope": "openid profile email api1",
      "state": "a2cb0e10e47141abbb208b0cc8c3123f",
      "nonce": "4dbb74883e34404d803ef29f61e8bebb"
    }
   }
IdentityServer4.ResponseHandling.AuthorizeInteractionResponseGenerator:Information: Showing login: User is not authenticated
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 480.88ms 302 
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/account/login?returnUrl=%2Fconnect%2Fauthorize%2Flogin%3Fclient_id%3Djs.tokenmanager%26redirect_uri%3Dhtt
p%253A%252F%252Flocalhost%253A4200%252Fauth.html%26response_type%3Did_token%2520token%26scope%3Dopenid%2520profile%2520email%25
20api1%26state%3Da2cb0e10e47141abbb208b0cc8c3123f%26nonce%3D4dbb74883e34404d803ef29f61e8bebb  
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program 
Files\dotnet\shared\Microsoft.NETCore.App\1.1.1\System.ComponentModel.Annotations.dll'. Skipped loading symbols. Module is 
optimized and the debugger option 'Just My Code' is enabled.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method 
CoreIdentityServer.Controllers.AccountController.Login (CoreIdentityServer) with arguments 
(/connect/authorize/login?client_id=js.tokenmanager&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauth.html&response_type=id_tok
en%20token&scope=openid%20profile%20email%20api1&state=a2cb0e10e47141abbb208b0cc8c3123f&nonce=4dbb74883e34404d803ef29f61e8bebb)
 - ModelState is Valid
'dotnet.exe' (CoreCLR: clrhost): Loaded 'brot4dwo.zsm'. Cannot find or open the PDB file.
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor:Information: Executing ViewResult, running view at path 
/Views/Account/Login.cshtml.
'dotnet.exe' (CoreCLR: clrhost): Loaded 'xjn13msf.l3j'. Cannot find or open the PDB file.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action 
CoreIdentityServer.Controllers.AccountController.Login (CoreIdentityServer) in 2609.9885ms
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/lib/jquery/dist/jquery.js  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/lib/bootstrap/dist/js/bootstrap.js  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 2696.8808ms 200 text/html; charset=utf-8
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/lib/bootstrap/dist/css/bootstrap.css  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:5001/css/site.css  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/lib/jquery-validation/dist/jquery.validate.js  
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware:Information: Sending file. Request path: '/lib/jquery/dist/jquery.js'. 
Physical path: 'C:\Projects\SW\RBCC\main\source\CoreIdentityServer\wwwroot\lib\jquery\dist\jquery.js'
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware:Information: Sending file. Request path: 
'/lib/jquery-validation/dist/jquery.validate.js'. Physical path: 
'C:\Projects\SW\RBCC\main\source\CoreIdentityServer\wwwroot\lib\jquery-validation\dist\jquery.validate.js'
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware:Information: Sending file. Request path: 
'/lib/bootstrap/dist/css/bootstrap.css'. Physical path: 
'C:\Projects\SW\RBCC\main\source\CoreIdentityServer\wwwroot\lib\bootstrap\dist\css\bootstrap.css'
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware:Information: Sending file. Request path: 
'/lib/bootstrap/dist/js/bootstrap.js'. Physical path: 
'C:\Projects\SW\RBCC\main\source\CoreIdentityServer\wwwroot\lib\bootstrap\dist\js\bootstrap.js'
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware:Information: Sending file. Request path: '/css/site.css'. Physical 
path: 'C:\Projects\SW\RBCC\main\source\CoreIdentityServer\wwwroot\css\site.css'
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 138.1093ms 200 application/javascript
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 170.431ms 200 text/css
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/js/site.js?v=Ynfdc1vuMNOWZfqTj4N3SPcebazoGXiIPgtfE-b2TO4  
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js  
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware:Information: Sending file. Request path: 
'/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js'. Physical path: 
'C:\Projects\SW\RBCC\main\source\CoreIdentityServer\wwwroot\lib\jquery-validation-unobtrusive\jquery.validate.unobtrusive.js'
Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware:Information: Sending file. Request path: '/js/site.js'. Physical path: 
'C:\Projects\SW\RBCC\main\source\CoreIdentityServer\wwwroot\js\site.js'
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 39.1718ms 200 application/javascript
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 66.1852ms 200 application/javascript
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 280.6117ms 200 application/javascript
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 311.4137ms 200 application/javascript
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 322.8023ms 200 text/css
The thread 0x4144 has exited with code 0 (0x0).
The thread 0x33f4 has exited with code 0 (0x0).
The thread 0xc7c has exited with code 0 (0x0).
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 POST 
http://localhost:5001/Account/Login?returnurl=%2Fconnect%2Fauthorize%2Flogin%3Fclient_id%3Djs.tokenmanager%26redirect_uri%3Dhtt
p%253A%252F%252Flocalhost%253A4200%252Fauth.html%26response_type%3Did_token%2520token%26scope%3Dopenid%2520profile%2520email%25
20api1%26state%3Da2cb0e10e47141abbb208b0cc8c3123f%26nonce%3D4dbb74883e34404d803ef29f61e8bebb 
application/x-www-form-urlencoded 251
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method 
CoreIdentityServer.Controllers.AccountController.Login (CoreIdentityServer) with arguments 
(IdentityServer4.Quickstart.UI.Models.LoginInputModel) - ModelState is Valid
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program 
Files\dotnet\shared\Microsoft.NETCore.App\1.1.1\System.Linq.Queryable.dll'. Skipped loading symbols. Module is optimized and 
the debugger option 'Just My Code' is enabled.
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\1.1.1\Microsoft.CSharp.dll'. 
Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'dotnet.exe' (CoreCLR: clrhost): Loaded 
'C:\Users\hubao\.nuget\packages\system.data.sqlclient\4.3.0\runtimes\win\lib\netstandard1.3\System.Data.SqlClient.dll'. 
Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'dotnet.exe' (CoreCLR: clrhost): Loaded 
'C:\Users\hubao\.nuget\packages\system.text.encoding.codepages\4.3.0\runtimes\win\lib\netstandard1.3\System.Text.Encoding.CodeP
ages.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'dotnet.exe' (CoreCLR: clrhost): Loaded 'C:\Program 
Files\dotnet\shared\Microsoft.NETCore.App\1.1.1\Microsoft.Win32.Primitives.dll'. Skipped loading symbols. Module is optimized 
and the debugger option 'Just My Code' is enabled.
The thread 0x3388 has exited with code 0 (0x0).
'dotnet.exe' (CoreCLR: clrhost): Loaded 
'C:\Users\hubao\.nuget\packages\microsoft.extensions.configuration.usersecrets\1.1.1\lib\netstandard1.5\Microsoft.Extensions.Co
nfiguration.UserSecrets.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory:Information: Executed DbCommand (391ms) 
[Parameters=[@__normalizedUserName_0='?' (Size = 256)], CommandType='Text', CommandTimeout='30']
SELECT TOP(1) [u].[Id], [u].[AccessFailedCount], [u].[ConcurrencyStamp], [u].[DataEventRecordsRole], [u].[Email], 
[u].[EmailConfirmed], [u].[IsAdmin], [u].[LockoutEnabled], [u].[LockoutEnd], [u].[NormalizedEmail], [u].[NormalizedUserName], 
[u].[PasswordHash], [u].[PhoneNumber], [u].[PhoneNumberConfirmed], [u].[SecurityStamp], [u].[TwoFactorEnabled], [u].[UserName]
FROM [AspNetUsers] AS [u]
WHERE [u].[NormalizedUserName] = @__normalizedUserName_0
'dotnet.exe' (CoreCLR: clrhost): Loaded 
'C:\Users\hubao\.nuget\packages\microsoft.aspnetcore.cryptography.keyderivation\1.1.1\lib\netstandard1.3\Microsoft.AspNetCore.C
ryptography.KeyDerivation.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory:Information: Executed DbCommand (20ms) 
[Parameters=[@__userId_0='?' (Size = 450)], CommandType='Text', CommandTimeout='30']
SELECT [role].[Name]
FROM [AspNetUserRoles] AS [userRole]
INNER JOIN [AspNetRoles] AS [role] ON [userRole].[RoleId] = [role].[Id]
WHERE [userRole].[UserId] = @__userId_0
Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory:Information: Executed DbCommand (3ms) 
[Parameters=[@__user_Id_0='?' (Size = 450)], CommandType='Text', CommandTimeout='30']
SELECT [uc].[Id], [uc].[ClaimType], [uc].[ClaimValue], [uc].[UserId]
FROM [AspNetUserClaims] AS [uc]
WHERE [uc].[UserId] = @__user_Id_0
Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware:Information: AuthenticationScheme: 
Identity.Application signed in.
CoreIdentityServer.Controllers.AccountController:Information: User logged in.
Microsoft.AspNetCore.Mvc.Internal.RedirectResultExecutor:Information: Executing RedirectResult, redirecting to 
/connect/authorize/login?client_id=js.tokenmanager&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauth.html&response_type=id_toke
n%20token&scope=openid%20profile%20email%20api1&state=a2cb0e10e47141abbb208b0cc8c3123f&nonce=4dbb74883e34404d803ef29f61e8bebb.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action 
CoreIdentityServer.Controllers.AccountController.Login (CoreIdentityServer) in 5249.4664ms
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 5277.118ms 302 
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/connect/authorize/login?client_id=js.tokenmanager&redirect_uri=http%3A%2F%2Flocalhost%3A4200%2Fauth.html&
response_type=id_token%20token&scope=openid%20profile%20email%20api1&state=a2cb0e10e47141abbb208b0cc8c3123f&nonce=4dbb74883e344
04d803ef29f61e8bebb  
IdentityServer4.Hosting.IdentityServerMiddleware:Information: Invoking IdentityServer endpoint: 
IdentityServer4.Endpoints.AuthorizeEndpoint for /connect/authorize/login
IdentityServer4.Endpoints.AuthorizeEndpoint:Error: User is not authenticated
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 247.9005ms 302 
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET 
http://localhost:5001/home/error?errorId=ae3b362f78d858c440b8841783bf0fea  
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method 
CoreIdentityServer.Controllers.HomeController.Error (CoreIdentityServer) with arguments (ae3b362f78d858c440b8841783bf0fea) - 
ModelState is Valid
'dotnet.exe' (CoreCLR: clrhost): Loaded 'oxemzl20.jl0'. Cannot find or open the PDB file.
Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor:Information: Executing ViewResult, running view at path 
/Views/Shared/Error.cshtml.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action 
CoreIdentityServer.Controllers.HomeController.Error (CoreIdentityServer) in 167.027ms
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 180.1413ms 200 text/html; charset=utf-8

Solution

  • It was my carelessness that I forgot to include the two js files in index.html.

    <script src="assets/css/jsrsasign.min.js"></script>  
    <script src="assets/css/oidc-client.min.js"></script>