c# - 用作另一个 IdentityServer 的外部身份提供者的 IdentityServer 无法正确重定向

标签 c# identityserver3 openid-connect identityserver4

在登录并同意后使用任何标准身份提供者(谷歌、Facebook)时,他们会重定向到我的主要身份服务器,并让它重定向到在其中注册的隐式客户端。我如何使用另一个身份服务器作为外部身份提供者实现相同的行为?

我的安全架构由两个身份服务器组成,主要一个 (v3) 使用另一个 (v4) 作为外部身份提供者。隐式客户端打开一个带有主要 IdentityServer 的弹出窗口。

我在执行以下流程时遇到问题:

Diagram showing authentication flow

充当外部 IdP 的身份服务器卡在端点上:

/connect/authorize/login?client_id=primaryIdentityServer&redirect_uri=https://primaryIdentityServer.example.com/signin-oidc&response_mode=form_post&response_type=code id_token&scope=openid profile email

错误信息:

拒绝将表单数据发送到“https://jsclient.example.com/#(...)”,因为它违反了以下内容安全策略指令:“form-action https://primaryIdentityServer。 example.com”。

外部身份提供者的主要 IdentityServer 配置:

var opts = new OpenIdConnectAuthenticationOptions {
    ClientId = "primaryServer",
    ClientSecret = "secret",
    RedirectUri = "https://primaryIdentityServer.example.com/signin-oidc",
    Authority = "https://externalIdPIdentityServer.example.com",
    ResponseType = "code id_token",
    Scope = "openid profile email",
    SignInAsAuthenticationType = signInAsType
};

app.UseOpenIdConnectAuthentication(opts);

在 IdentityServer 中注册的 IdentityServer 主要用作外部 IdP:

new Client
{
    ClientId = "primaryServer",
    AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
    RedirectUris = new List<string>
    {
        "https://primaryIdentityServer.example.com/signin-oidc"
    },
    ClientSecrets = 
    {
        new Secret("secret".Sha256())
    },

    AllowedScopes =
    {
        IdentityServerConstants.StandardScopes.OpenId,
        IdentityServerConstants.StandardScopes.Profile,
        IdentityServerConstants.StandardScopes.Email
    },
    AlwaysIncludeUserClaimsInIdToken = true
}

编辑:我注意到,当我尝试在 /permissions 端点检查我的应用程序权限并使用外部 IdentityServer 进行身份验证时,我被重定向到权限端点,没有任何问题。

编辑:我尝试切换到身份服务器之间的隐式流。从 response_type 中删除了 secrets,code 并将隐式设置为允许的授权类型,我在向我的 js 客户端发送发布数据时仍然收到相同的错误,因此看来所选流程(混合或隐式)与此无关问题。

编辑:我检查了身份验证过程卡住的端点的来源:

<form method='post' action='https://primaryIdentityServer.example.com/signin-oidc'><input type='hidden' name='id_token' value='{token}' />
<input type='hidden' name='access_token' value='{token}' />
<input type='hidden' name='token_type' value='Bearer' />
<input type='hidden' name='expires_in' value='3600' />
<input type='hidden' name='scope' value='openid profile' />
<input type='hidden' name='state' value='OpenIdConnect.AuthenticationProperties={props}' />
<input type='hidden' name='session_state' value='{state}' />
</form><script>(function(){document.forms[0].submit();})();</script>

带有查询参数: https://externalIdPIdentityServer.example.com/connect/authorize/consent?client_id=primaryServer&redirect_uri=https://primaryIdentityServer.example.com/signin-oidc&response_mode=form_post&response_type=token id_token&scope=openid profile&state={state}&nonce= {nonce}

所以错误的原因很奇怪:

拒绝将表单数据发送到“https://jsclient.example.com/#(...)”,因为它违反了以下内容安全策略指令:“form-action https://primaryIdentityServer。 example.com”。

因为在任何地方都没有提到 jsclient.example.com。

编辑:问题仅出现在 Chrome 中,不会出现在 Firefox 或 IE Edge 中。

最佳答案

我已经开始在 IdentityServer4 问题中搜索“chrome”和“csp”关键字并找到了这个:https://github.com/IdentityServer/IdentityServer4/issues/659

事实证明需要更改授权响应的表单操作 CSP,并且 IdentityServer4 版本从 1.0.1 开始放宽此策略指令。

我将 IdentityServer4 从 1.0.0 更新到 1.0.2,它解决了这个问题。

关于c# - 用作另一个 IdentityServer 的外部身份提供者的 IdentityServer 无法正确重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41854600/

相关文章:

c# - Fluent Nhibernate 保存子实体

c# - .Net MVC 实体和 ViewModel...相同还是独立?

windows-authentication - Thinktecture IdentityServer v3 与 WindowsAuth

google-app-engine - OpenId Connect 端点返回 'not found'

c# - 如何创建一个多目标但针对每个框架不同的 dll 的 .NET Core 库?

c# - 是否有一种正确的方法来菊花链式连接类并以正确的方式调用它?

oauth-2.0 - IdentityServer 3返回invalid_client

c# - 没有可用于 token 的 SecurityTokenValidator

go - 使用存储在 Golang 自己的数据库中的用户创建 Google 身份验证服务

amazon-web-services - Kubernetes 预计服务帐户 token 到期时间问题