angular - 使用 Angular oAuthservice 和 Identity server 4 设置自定义域

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

我们有 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
});

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

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

相关文章:

c# - ASP.NET Core Web API 验证错误处理

objective-c - 使用 OAuth/XAuth(?) 以编程方式登录 Facebook

angular - 闪屏。 ( Angular 2)

angular viewChild 用于 ngFor 中的动态元素

forms - 如何在 Angular 2 final 中的异步表单验证方法中进行 http 调用?

asp.net-mvc - 类型 'DefaultInlineConstraintResolver' 的内联约束解析器无法解析以下内联约束 :

javascript - 使用 Web.config 中的选项填充 HTML 选择

java - Magento oauth 与 android

java - 使用 DropboxAPI 进行 OAuth,无需手动复制 url 进行授权

javascript - 如何在 Angular 2 中为不同的路线设置标题?