【问题标题】:OIDC Connect and Auth Code Flow with PKCE in Angular and Identity Server 4在 Angular 和 Identity Server 4 中使用 PKCE 进行 OIDC 连接和验证代码流
【发布时间】:2019-09-25 12:51:33
【问题描述】:

我正在为我的 Angular 应用程序使用 angular-auth-oidc-client 包。我已经在 Identity Server 3 中使用了很长时间,并且在使用隐式流时它运行良好。但是当尝试在 Identity Server 4 上使用 PKCE 的身份验证代码流时,我无法让它工作。

我的身份验证服务器客户端配置如下:

new Client
{
    ClientId = "My.Angular.App",

    // no interactive user, use the clientid/secret for authentication
    AllowedGrantTypes = GrantTypes.Code,

    // secret for authentication
    ClientSecrets = new List<Secret> { ... },

    RedirectUris = new List<string> { ... },

    AllowedScopes = new List<string> { ... },
}

angular-auth-oidc-client的配置如下:

{
    "stsServer": "https://auth2.test.hsahealthplan.com",
    "redirect_url": "...",
    "client_id": "My.Angular.app",
    "response_type": "code",
    "scope": "...",
    "post_logout_redirect_uri": "...",
    "start_checksession": false,
    "silent_renew": true,
    "silent_renew_url": "...",
    "post_login_route": "...",
    "forbidden_route": "...",
    "unauthorized_route": "...",
    "log_console_warning_active": true,
    "log_console_debug_active": false,
    "max_id_token_iat_offset_allowed_in_seconds": 300
}

当我在本地运行 Identity Server 4 并将 stsServer 设置为 https://localhost:5000 时:

当我在本地运行 Identity Server 4 并将 stsServer 设置为 http://localhost:5000 时:

当我尝试使用真正的身份验证服务器进行身份验证时,我们有其他应用程序正在使用该服务器进行身份验证:

我不确定为什么我从身份验证服务器收到错误代码 405,或者为什么它在本地也不起作用。如果有人有任何建议,将不胜感激。

【问题讨论】:

    标签: angular openid-connect


    【解决方案1】:

    可能 IdentityServer 实现包含与 IdentityServer 内部 CORS 服务冲突的 CORS 中间件 (app.UseCors(...))。 app.UseCors(...) 应该在 Startup.Configure 中的 app.UseIdentityServer 之后调用

    【讨论】:

      【解决方案2】:

      另一个 ID4 服务器不接受您的请求是合乎逻辑的,因为它没有在其中注册您的应用程序。该 ID4 服务器不知道客户端信息,因此它将拒绝来自您的应用的请求。

      调用https://localhost:5000 失败,因为您在某处错误配置了 SSL,从提供的信息中我不清楚在哪里以及如何使用。调用http://localhost:5000 可能会失败because you forgot to turn off SSL。 CORS也可能配置错误,您从应用程序主域以外的域请求的每个资源都需要将您的域作为“access-control-allow-origin”标头中的值。因此,如果您在 app.com 上托管的应用向 ID4.com 请求某些内容,则所请求的资源需要在“access-control-allow-origin”标头中包含 app.com。

      【讨论】:

        猜你喜欢
        • 2021-01-29
        • 2021-05-12
        • 2020-06-28
        • 2021-03-06
        • 1970-01-01
        • 2019-11-23
        • 1970-01-01
        • 2022-01-13
        • 2022-07-07
        相关资源
        最近更新 更多