11

我正在关注 https://www.scottbrady91.com/Angular/SPA-Authentiction-using-OpenID-Connect-Angular-CLI-and-oidc-clienthttps://www.scottbrady91.com/Angular/Migrating-oidc -client-js-to-use-the-OpenID-Connect-Authorization-Code-Flow-and- PKCE 在 SPA(Angular)中实现 OIDC

我正在使用 aspboilerplate 集成 IdentityServer

我已经按照上述文章设置了所有内容,并且能够导航到外部身份验证提供程序,并且还能够输入所需的凭据。

在重定向到 Angular 时,我收到 400 - 错误请求。这是详细信息

回调网址:

http://localhost:4200/auth-callback?code=b74f38054d4becadaa3c45ce58a83c892e0d25e7fc4bfcc1ef29ce369b477596&scope=openid%20profile%20api1&state=18af0415b22b4614882d3e31113e2717&session_state=yP4rCdCetarKTsX6X0JXYTeV_1Xo8dud9V2FnT-14QE.db913b7a39e26220d8ac07de5a523eb2

Cookies : 请求发送 9095 字节的 Cookie 数据:

    .AspNetCore.Antiforgery.xkdte50z5pg=CfDJ8FAKJpEizERFtUzdjBClgctpGC-BWtg81DZ33kUapCDBb84U7ILfbqhExQzI3oVOWReKh72cV8hdROZcCh6wK7tbwl14PnWzNIECZGxyYx-K3MINQnZEp3cp-Ury1Z4KaRHs7mqvmf6oc30h6Q-oFxI
    idsrv.external=chunks-2
    idsrv.externalC1=CfDJ8FAKJpEizERFtUzdjBClgcum3jNb_Pj5sm5cfWLtKGcBqkU1VIUHlMdupOgnYwqTNw3bjxOoeVbCR1YR9y6Y2Q6zZvxX2juNv1iiUTwVIcTAG99R0QU8Ki1EJ8uOvaVN-BgUFNXYzcrct69nxfTGj5Ay2wL18-ziLczxnqurAbgTVkgyZs6IWHgtbOwyoyJb3klbQUkt4nmNZbwNSzeYknhDq7ohwEqeva51TIw73lciD2bJpJZnxUFx9eRI7FiJcf6qM3iYzvQ9R1-IRAmTleGEul_KY0eEcf8srxjPDgCRvj_Chy14N0rJdvWvrgio2yfdKTiCam2y-xPporU1oBOupt4zuaKsnPlHzzY9NksO_Gp7TTXJi91d3P2rl9FtBbQVQQDgpuN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0o2Y0JMEg9gsExTh1K3Z_e_DCnfJl3XGgB6Q5rX_qzcvqwyldPn1xJyXealA5KCi38hqsI0wy5-LZhiIUt6PEQX_WNF5wiL9jkT_6-qVfUhlRB87tcqx6YHwdwlYUErsNkrRwZJQrtXxDJoZwEWYy31Ehpi2XVoKTksNGdvHbJcPtFBt7BactgMy6MRu0LVTI8XFhVaG-9LaiHAq9U3c2vblpNjdlBW0nrujZo5MaV5xroyrL3PxZ3j9oj3FzbtgcN_ys5J8FMdhTBAaN5V_YtAWpBH1kP527q_raw1wWdnIvLKQk9hsQJqdldZoKM6mZgyE5_lAWzLs1KN4xwD7Gbz3uQVoaIdIGGsW1iXhB6wJ7WeN9vD6kAJBiI9aHn_iJLmh-QPEWPdMntVipec4UXAACVXPX_QmOvFYxdVhSQp9tdmzpvAfVpQpsbrF29ro0olru0Aimv73wMp4UtIacGSu2T7rHfwkXJ05o9IDuUnjOC9oXMhxLvz_dBwjHeHt_B3BvBQ-XNSEQra0fD0MzJ3GBRqK1vUWRJQzaUmfZF5aE39az8qoRZBAYKFrAzqE8Y2IsEK6UhrJj4QuJ03l_skguhXuraLyH-IO6fnRqF5lZQgO81RIZKDvRlhNrcGJsM6yOotUXXTpVz9xjOtn1rMO1woO0up8kr16vlcRKp_TUh_VqDvV-AbY93ZYBUuvVUiLonGaOK7V3X7uqJGFsh0f27hy7CKYyjviPLo9eEs_oMsjh34cLEzDEPSZtgdqbv6_82ruVRA6S5wKWr6v3HluBVjJP7Q8iBJbLzFfl85ihIjj04hYZQmBUx0E0a646NVETdibYC7zcmdtGOUb045Nifb3A

身份服务器配置:

public static class IdentityServerConfig
{
    public static IEnumerable<ApiResource> GetApiResources()
    {
        return new List<ApiResource>
        {
                  new ApiResource("api1", "My API")
        };
    }

    public static IEnumerable<IdentityResource> GetIdentityResources()
    {
        return new List<IdentityResource>
    {
        new IdentityResources.OpenId(),
        new IdentityResources.Profile()
    };
    }

    public static IEnumerable<Client> GetClients()
    {
        return new List<Client>
        {
             new Client
            {
                   ClientId = "angular_spa",
                    ClientName = "Angular 4 Client",
                    AllowedGrantTypes = GrantTypes.Code,
                    RequirePkce = true,
                    RequireClientSecret = false,
                    AllowedScopes = new List<string> {"openid", "profile", "api1"},
                    RedirectUris = new List<string> {"http://localhost:4200/auth-callback", "http://localhost:4200/silent-refresh.html"},
                    PostLogoutRedirectUris = new List<string> {"http://localhost:4200/"},
                    AllowedCorsOrigins = new List<string> {"http://localhost:4200"},
                    AllowAccessTokensViaBrowser = true
            }
        };
    }
}

角度配置:

export function getClientSettings(): UserManagerSettings {
  return {
    authority: 'http://localhost:44380/',
    client_id: 'angular_spa',
    redirect_uri: 'http://localhost:4200/auth-callback',
    post_logout_redirect_uri: 'http://localhost:4200/',
    response_type: "code",
    scope: "openid profile api1",
    filterProtocolClaims: true,
    loadUserInfo: true
  };
}

请让我知道可能出了什么问题

编辑:到目前为止我发现的是

  1. 即使使用另一个 Angular oidc 客户端angular-auth-oidc-client,我也陷入了同样的错误
  2. 使用 JS 客户端(https://github.com/IdentityServer/IdentityServer4/tree/master/samples/Quickstarts/6_JavaScriptClient),它按预期工作。但由于我们有 Angular 作为前端,我通过包含所需的 JS 库在 Angular 中实现了 JS 示例,令我惊讶的是,我面临同样的问题
  3. 当我复制 URL 并粘贴到另一个浏览器中时,call-back会调用该组件。所以看起来 Header & Cookie 有问题。这是我从 Fiddler 收到的请求的完整数据

    GET http://localhost:4200/call-back?code=7bc6c3d343067f2ede3ed86268e3622bb909cb8df5d75d2f223b335bd75b730c&scope=openid%20profile%20api1&state=86215491d41a4c3c83d52007edf372cd&session_state=ibjjr0YMpGp_UZ1ezmUMusoAIpht25ySKfq8hoCKHXQ.e7f8f959a82f09b830a9635911c0b9f3 HTTP/1.1

    主机:localhost:4200 连接:keep-alive 升级-不安全请求:1 用户代理:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36 Sec-Fetch-Mode: 导航接受: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng, / ;q=0.8,application/signed-exchange;v=b3 Sec-Fetch-Site: none 接受编码: gzip, deflate, br Accept-Language: en-US,en;q=0.9

    Cookie: .AspNetCore.Antiforgery.xkdte50z5pg=CfDJ8FAKJpEizERFtUzdjBClgcvmHhFjLJ4WDhku77bzpIxGI20-YRukepOXg6hGG4AUWzSGKXSWmy0Ie9tQFsXnWx0sUUlh0EAOij8y18d_96_-FVyCrPhtQ0JRtEXvhPXLxqum0sIJmwFD1116QRU-E5A; idsrv.external=chunks-2;idsrv。MKJYCXZt6vpbZtRl9Qp5K2x2N5V3ChOe1Qpwb40FjU4_UhbkBbiqr5N2R_RfGS8JH5hDDn09LEZojC6YHq_YCc0B8QwlFfiThYCE1QvHpAUJ-Yk1HDVJ2tNW_y04CXwMheBCMB90c2SmyLY6w59G8vKOLk-CHrn7dfL6uaECsNcdieFB_pb3N66tjGd38-dS3DCULT7xZMAxhdZoBgrmehUX2F3dvP6t9snKXc8QrUUkeogFzOpVOCdJKUMwsZLgJjXMfq_psFc3gtbQEGi_n7nH-kHkigntSgaieblXuVzqV0UGCJr3pcEsCt5I2kWGZmUiUhEOLLBApK2vvDl8WgOkGmyIQmVEUa-UDp5XoJeZ8n-8ZVlPbFUg4CFuvCBserjD1b-WTOYgam1ufRRImo0OlsAVDNkZBsc-3SJ-jMhwhukhnE4AycHlB3o5inVRUWvjWckrTetL3d5ivj6rwI6sLQEZXnpBIwDZDTbMnCNFuaMaPT3q1l1MxSRncvF4xolSQraCjjAdpLVtfNM1bBC_1c_3a0z97OlhDFOM9sppnCqWIXdwcNKdj1B4dVdMUescRrVgy; idsrv。yC8nnCe_icrNO1W_boKRaJJ9EOVa8iHJIRo1QxSGsbYMHV-Fghng-7klfIZWcsuMgx_YJEmTS7clsFKG4kjVEjxQ9VOcVzjjtx4sfuelkEuqdr7cMwbJneRwoiLsIGVPMxSZphdgHb_mn3Hm6Nbb07EibbRIl-Y96fPZCqDGhq1R6DONprDwXJ305kvEspHeQayWiwXOoGg6XQJNtMf9aBrPc3ocQWvTjoRQj6GmpqyEXODhVYuePHiEmqh8XAVdLuIEFra6INZYmev4h8eWMKX3cle2WivccXEe3e5X175Vg1Yi23uw7lOu5o0_-G68; idsrv.session=5d538478b846f725df5730950f1b193e;.AspNetCore.Identity。

    HTTP/1.1 400 错误请求连接:关闭

这是我在浏览器中看到的

在此处输入图像描述

4

4 回答 4

6

正如您已经发现确切的问题是标题限制并通过限制 cookie 大小来解决它,但限制 cookie 大小可能不是每次都可以解决的问题。angular 不接受大标题数据的主要原因是 bcs angular 使用 node servewebpack-dev-server和那里是节点 js 中标头大小的限制,您可以在下面找到相关问题

存在大型 cookie 时,ng serve 无法提供页面

由于节点将标头大小限制为 8kB,导致 400 错误请求

更新 npm run 以修复最新 nodejs 版本中的 hpe_header_overflow

使 HTTP_MAX_HEADER_SIZE 可配置

所以不要使用ng serveusing 命令

node --max-http-header-size=16385 ./node_modules/@angular/cli/bin/ng serve

应该是您问题的解决方案

于 2019-08-27T04:44:11.303 回答
3

出于某种原因,Angular 不接受那么多数据(Cookie)作为 Header 的一部分。虽然这适用于 JS 客户端,但我不确定为什么 Angular 会发生这种情况。

Account/ExternalController.cs在开发的初始阶段,出于某种原因,我在IdentityServer中注释掉了以下几行

// delete temporary cookie used during external authentication
await HttpContext.SignOutAsync(IdentityServer4.IdentityServerConstants.ExternalCookieAuthenticationScheme);

当这一行被注释掉时,将会有额外的 Cookie 在回调期间发布到 Angular。

取消注释上述行将删除临时 Cookie,并且在回调期间将有更少的标头数据,它会调用相应的 Angular 回调组件并设置不记名令牌。

需要澄清

  1. 如果有人可以分享为什么 Angular 在与 JS 客户端完美配合的情况下不接受大型标头数据。
  2. 尽管 Angular 说请求错误,但我无法找到引发此错误的位置(Angular 中的哪一层)。我什至没有看到一行错误,我可以从中得到一些关于错误原因的提示(大标题数据)

如果一些专家可以分享他们在上述几点上的经验,那么了解 Angular 的工作原理将非常有帮助。

如果由于任何原因,您无法限制标头大小,则增加节点的 --max-http-header-size。请参阅 https://stackoverflow.com/a/57667786/2922388了解如何操作。

于 2019-08-23T18:32:20.563 回答
1

只需尝试一些修复即可。首先 -RedirectUris似乎可疑,因为它包含多个值, - 根据http://docs.identityserver.io/en/latest/topics/clients.html - 声明这List<string>可能是问题的根源。

接下来,以服务器端配置为例https://github.com/IdentityServer/IdentityServer4.Demo/blob/master/src/IdentityServer4Demo/Config.cs

    new Client
    {
       ...
        RequireClientSecret = false,
        RequireConsent = false,

        AllowedGrantTypes = GrantTypes.Code,
        AllowedScopes = { "openid", "profile", "email", "api" },

        AllowOfflineAccess = true,
        RefreshTokenUsage = TokenUsage.ReUse

    }

让我们假设AllowedScopes应该包括强制email范围,然后GetIdentityResources()需要最后修复:

    public static IEnumerable<IdentityResource> GetIdentityResources()
    {
        return new List<IdentityResource>
        {
            new IdentityResources.OpenId(),
            new IdentityResources.Profile(),
            new IdentityResources.Email(),
        };
    }

由于 SPA 代码超出了此处的范围,因此要正确执行流程,请遵循以下示例:

https://github.com/IdentityServer/IdentityServer4.Demo/ ,

于 2019-08-22T07:20:50.290 回答
1

也许您在路由redirect_url配置中混淆了一些东西?

根据您发布的客户端和服务器的配置,redirect_url应该是:

http://localhost:4200/auth-callback `

然而,在截图路径是/call-back,不是/auth-callback

我会检查配置(客户端和服务器)和 Angular 路由器是否都/auth-callback配置了相同的路径。

于 2019-08-22T14:00:04.290 回答