我对在我的应用程序中实现身份验证/授权还很陌生,所以我可能在这里遗漏了一些明显的东西。
我正在使用 Angular 和 oidc-client.js 与我的 STS (IdentityServer4) 进行通信,并且我正在设置我的 Angular 应用程序以通过身份服务器登录,然后重定向回我的客户端网站。但是,我在尝试登录时遇到了如何从客户端发送在我的 IS4 服务器中定义的客户端机密的问题。我收到一个错误,包括以下日志输出:
"Name": "Client Authentication Failure", "EventType": "Failure", "Id": 1011, "Message": "Invalid client secret"
我定义我的 UserManager 如下:
constructor() {
const stsSettings = {
authority: Constants.stsAuthority,
client_id: Constants.clientId,
redirect_uri: `${Constants.clientRoot}signin-callback`,
scope: 'openid profile myApi',
response_type: 'code',
post_logout_redirect_uri: `${Constants.clientRoot}signout-callback`
};
this.userManager = new UserManager(stsSettings);
}
根据文档 here 没有添加客户端密码的配置。我在这里遗漏了什么吗?
My Client 在 IdentityServer 中定义如下:
new Client
{
ClientId = "interactive",
ClientSecrets = { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.Code,
RedirectUris = { "https://localhost:44300/signin-oidc" , "https://localhost:5001/signin-callback"},
FrontChannelLogoutUri = "https://localhost:44300/signout-oidc",
PostLogoutRedirectUris = { "https://localhost:44300/signout-callback-oidc", "https://localhost:5001/signout-callback" },
AllowOfflineAccess = true,
AllowedScopes = { "openid", "profile", "myApi" }
}
编辑
我尝试通过变量 client_secret: 2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b
和作为 extraQueryParams: { client_secret: "2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b" }
的成员以角度传递“秘密”的 sha256 (2bb80d537b1da3e38bd30361aa855686bde0eacd7162fef6a25fe97bf527a25b)。
这两种情况都不适合我。
答案 0 :(得分:-1)
我相信到目前为止您的配置是正确的,但您错过了传递 client_secret
参数。
constructor() {
const stsSettings = {
authority: Constants.stsAuthority,
client_id: Constants.clientId,
client_secret: 'Your Secret',
redirect_uri: `${Constants.clientRoot}signin-callback`,
scope: 'openid profile myApi',
response_type: 'code',
post_logout_redirect_uri: `${Constants.clientRoot}signout-callback`
};
this.userManager = new UserManager(stsSettings);
}
注意:请记住,您需要将 client_secret
参数的值作为散列机密传递(不要传递纯文本机密,否则会失败),您可以找到ID4 数据库中的哈希值。