我们有 Angular 门户,它与身份服务器 4 进行通信,并且它与我们自己的域配合得很好。我们希望添加对自定义域的支持,为此我们将域名存储在数据库中,每当打开任何 Angular 门户链接时,我们都会从数据库中获取域名并分配给 authConfig,如下所示:
Object.assign(authConfig, { issuer: domainNam });
this.oauthService.configure(authConfig);
this.oauthService.tokenValidationHandler = new JwksValidationHandler();
this.oauthService.loadDiscoveryDocumentAndTryLogin().then(() => {
// .... rest of the code
});
它设置当前发行者的域名,但它不会重定向到登录页面,而是向我显示以下错误:
链接是这样的:
这里出了什么问题?
如果未设置发行者,则它可以正常工作,但当我动态设置发行者时,就会产生此问题。
authConfig如下:
export const authConfig: AuthConfig = {
// Url of the Identity Provider
issuer: environment.identityServer.authority,
// URL of the SPA to redirect the user to after login
redirectUri: window.location.origin + "/auth-callback",
// The SPA's id. The SPA is registerd with this id at the auth-server
clientId: environment.identityServer.client_id,
// set the scope for the permissions the client should request
// The first three are defined by OIDC. The 4th is a usecase-specific one
scope: environment.identityServer.scope,
logoutUrl: environment.identityServer.authority + '/Account/Logout',
}
最佳答案
以下是您可以注意解决的几点:
1) 颁发者 -> 授权服务器的颁发者标识符//即使从当前环境文件中读取也不应创建任何问题,请确保在相应环境中设置适当的 key
2)redirectUri -> 您的重定向网址//确保在 Identity Manager 中配置此回调,这可能是原因之一
3) 授权 header -> 我相信您已经从网络服务器传递了 key ,请注意良好实践
现在终于,
Object.assign(authConfig, { issuer: domainNam }); // step 1
this.oauthService.configure(authConfig); // step 2
对于上面的代码,请确保您是awaiting如果从服务器读取域名,则在步骤 1 中,然后馈送到步骤 2
我相信正如您所说,它仅在动态设置时才起作用,考虑到上述因素,您的身份验证应该起作用。
关于angular - 使用 Angular oAuthservice 和 Identity server 4 设置自定义域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56908120/