【问题标题】:Unknown client or client not enabled未知客户端或客户端未启用
【发布时间】:2020-06-25 00:00:10
【问题描述】:

我收到了这个错误:

只有在我移除重定向后才能成功访问

这是 Identity Server 4 端:

new Client {
    RequireConsent = false,
    ClientId = "ClientApp",
    ClientName = "SPA Client App",
    AccessTokenType = AccessTokenType.Jwt,
    AllowedGrantTypes = GrantTypes.Implicit,
    AllowedScopes = { "openid", "profile", "email", "api.read" }, 
    RedirectUris = {"http://localhost:4200/auth-callback"},
    PostLogoutRedirectUris = {"http://localhost:4200/"},
    AllowedCorsOrigins = {"http://localhost:4200"},
    AllowAccessTokensViaBrowser = true,
    AccessTokenLifetime = 3600
},

和客户端:

export function getClientSettings(): UserManagerSettings {
    return {
        authority: 'http://localhost:5000',
        client_id: 'ClientApp',
        redirect_uri: 'http://localhost:4200/auth-callback',
        post_logout_redirect_uri: 'http://localhost:4200/',
        response_type: 'id_token token',
        // scope: 'openid profile BankOfDotNet.API',
        scope: 'openid profile email api.read',
        filterProtocolClaims: true,
        loadUserInfo: true,
        automaticSilentRenew: true,
        silent_redirect_uri: 'http://localhost:4200/silent-refresh.html'
    };
}

显示另一个错误,我无法理解它是否与之前的相同。

按要求记录:

IdentityServer4.Validation.AuthorizeRequestValidator:Error: Unknown client or not enabled: SPAClient
{
  "SubjectId": "anonymous",
  "RequestedScopes": "",
  "Raw": {
    "client_id": "SPAClient",
    "redirect_uri": "http://localhost:4200/fetch-data",
    "response_type": "code",
    "scope": "openid profile bankOfDotNetApi",
    "state": "b1c4a9eebe704650a6301a4fa633d558",
    "code_challenge": "OWv8xEW0iHKVQTDUTqxybVe4cQXAd2mdJIWZ8Budni8",
    "code_challenge_method": "S256",
    "response_mode": "query"
  }
}
IdentityServer4.Endpoints.AuthorizeEndpoint:Error: Request validation failed
IdentityServer4.Endpoints.AuthorizeEndpoint:Information: {
  "SubjectId": "anonymous",
  "RequestedScopes": "",
  "Raw": {
    "client_id": "SPAClient",
    "redirect_uri": "http://localhost:4200/fetch-data",
    "response_type": "code",
    "scope": "openid profile bankOfDotNetApi",
    "state": "b1c4a9eebe704650a6301a4fa633d558",
    "code_challenge": "OWv8xEW0iHKVQTDUTqxybVe4cQXAd2mdJIWZ8Budni8",
    "code_challenge_method": "S256",
    "response_mode": "query"
  }
}
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 186.6231ms 302 
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:5000/home/error?errorId=CfDJ8CQhqAOzyZ9FnWMOkakiUDM48vI_2dxE-C2BufLYKmWsaswgqMctLthhXKjSgwSdgWakjV1UpkzAwMl4aeQRoa_OK7NBBmGejbq8r8kZ8ZryGFMBXhFPTP_auWF6ZU0qSRpm6hRYKpaFsJkA9V0mbmpcHeHTok7levfWugV3Ysiu0xRCRYz7iSM590AlkEjiHCLjrFnGTaGTY7pFGywlcfeWbeOpfkbBVNqeqe0YgkJzFmBouS4k7XdOhAL6afG8j2Zh33Cw4yDMYFMEXIOLWswYoHy2Q0t4G5gpJ2VBBoIgtRV2LeVHrw45qpIUjNOFNnI1g-rD_eTgb0pCjXCLJfR_X6zIO1tJArXHrUTLyAMt  
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Route matched with {action = "Error", controller = "Home"}. Executing controller action with signature System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Error(System.String) on controller IdentityServer4.Quickstart.UI.HomeController (BankOfDotNet.IdentitySvr).
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executing action method IdentityServer4.Quickstart.UI.HomeController.Error (BankOfDotNet.IdentitySvr) - Validation state: Valid
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action method IdentityServer4.Quickstart.UI.HomeController.Error (BankOfDotNet.IdentitySvr), returned result Microsoft.AspNetCore.Mvc.ViewResult in 7.5635ms.
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executing ViewResult, running view Error.
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor:Information: Executed ViewResult - view Error executed in 21.4364ms.
Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Information: Executed action IdentityServer4.Quickstart.UI.HomeController.Error (BankOfDotNet.IdentitySvr) in 50.3452ms
Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 72.7919ms 200 text/html; charset=utf-8
The thread 0x2c44 has exited with code 0 (0x0).
The thread 0x46d0 has exited with code 0 (0x0).

我是新的,这就是我们添加这样的日志的原因,我不知道如何在最简单的视图中添加它。

【问题讨论】:

  • 您是否在端口 5000 上运行您的身份服务器。您也可以发布 auth-callback.component.ts 文件的代码,尤其是第 10-25 行,以便更好地了解正在发生的事情
  • 如您所知,IdentityServer 生成有用的日志,您愿意分享日志吗?这是找出问题所在的最简单方法。
  • 日志被添加到帖子中

标签: asp.net .net angular identityserver4


【解决方案1】:

你的客户定义说

ClientId = "ClientApp",

但在日志中,是这样说的:

"client_id": "SPAClient",

你对clientId感到困惑吗?

【讨论】:

    猜你喜欢
    • 2019-07-25
    • 2020-05-01
    • 2016-07-20
    • 2021-12-22
    • 1970-01-01
    • 2020-02-27
    • 1970-01-01
    • 2013-06-06
    • 2017-02-08
    相关资源
    最近更新 更多