使用Angular oAuthservice和Identity Server 4设置自定义域

时间:2019-07-05 19:04:06

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

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

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

enter image description here

链接是这样制作的:

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

1 个答案:

答案 0 :(得分:2)

以下是您可以解决的几点:

1)颁发者->授权服务器的颁发者标识符// //即使从当前环境文件中读取也不应该创建任何问题,请确保在相应的环境中设置了适当的密钥

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

3)授权标头->我相信您已经从Web服务器传递了秘密密钥,请按提示进行良好练习

现在终于,

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

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

对于上述代码,如果从服务器读取域名,然后进入步骤2,请确保您在步骤awaiting

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