【问题标题】:Setting custom domain using Angular oAuthservice and Identity server 4使用 Angular oAuthservice 和 Identity server 4 设置自定义域
【发布时间】:2019-07-14 04:15:51
【问题描述】:

我们有与身份服务器 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
});

它为发行者设置了当前的域名,但它不会重定向到登录页面,而是向我显示以下错误:

链接是这样的:

https://account.ourDomainName.io/connect/authorize?response_type=id_token%20token&client_id=WebApiImplicitClientId&state=OcTztAVWhhgJtfQYwXvJO3B9RD6rGkeKpQxM99ki&redirect_uri=https%3A%2F%2Fportal.ourDomainName.io%2Fauth-callback&scope=openid%20profile%20email%20aitapi&nonce=OcTztAVWhhgJtfQYwXvJO3B9RD6rGkeKpQxM99ki

这里出了什么问题?

如果没有设置发行者,那么它工作正常,但是当我动态设置发行者时,它会产生这个问题。

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',
}

【问题讨论】:

  • 或许here的答案对你有帮助。
  • 嗨,谢谢,但这不是我要找的东西:|
  • 您从身份服务器 4 得到什么错误(如果有)?
  • @cheesemacfly - 错误提示:抱歉,出现错误:未授权客户端
  • @Neel 您需要弄清楚为什么会出现此错误,它应该有助于解决您的问题。

标签: angular asp.net-web-api oauth identityserver4


【解决方案1】:

您可以注意解决以下几点:

1) issuer -> 授权服务器的 issuer 标识符 // 即使从当前环境文件中读取也不应该产生任何问题,确保在各自的环境中设置了适当的密钥

2) redirectUri -> 您的重定向 url // 确保在 Identity Manager 中配置了此回调,这可能是原因之一

3) 授权标头 -> 我相信您已经从网络服务器传递了密钥,请注意

现在终于,

Object.assign(authConfig, { issuer: domainNam }); // step 1

this.oauthService.configure(authConfig); // step 2

对于上述代码,如果从服务器读取域名,请确保您在第 1 步时为awaiting,然后输入到第 2 步

我相信正如您所说,它仅在动态设置时才起作用,考虑到上述考虑,您的身份验证应该起作用。

【讨论】:

  • @Neel 你试过这个吗?让我知道它是否适合你
  • 您好,感谢您的回答。我今天去看看。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-10-06
  • 1970-01-01
  • 1970-01-01
  • 2019-08-04
  • 2019-12-28
  • 2018-07-12
  • 1970-01-01
相关资源
最近更新 更多