OAuthService错误的发行者错误(angular-oauth2-oidc)

时间:2018-06-12 14:26:03

标签: angular azure oauth-2.0 azure-active-directory angular-oauth2-oidc

我目前正在尝试在我的角度应用程序中实现azure广告身份验证。不幸的是我遇到了一些问题。以下代码为我提供了我期待的访问令牌。要在我的api中实现它,我想使用OpenIDConnect。

export class AppComponent implements OnInit {
  title = 'Sign in test';

  constructor(private oauthService: OAuthService) {

  }

  private async ConfigureAuth(): Promise<void> {
    this.oauthService.configure({
      loginUrl: 'loginUrl',
      clientId: 'clientId',
      resource: 'resource',
      logoutUrl: 'logoutUrl',
      redirectUri: window.location.origin + '/',
      scope: 'openid',
      oidc: false
    });   
    this.oauthService.setStorage(sessionStorage);  
  }

  async ngOnInit() {
    await this.ConfigureAuth();

    this.oauthService.tryLogin({});

    if(!this.oauthService.getAccessToken()) {
      await this.oauthService.initImplicitFlow();
    }

    console.log(this.oauthService.getAccessToken());
  }
}

登录仍然有效,因为它为我提供了访问令牌,但当我将oidc设置为true时,它会给我以下错误:

angular-oauth2-oidc.js:1146 Error validating tokens
(anonymous) @ angular-oauth2-oidc.js:1146

Wrong issuer: https://sts.windows.net/{tenantid}/

ERROR Error: Uncaught (in promise): Wrong issuer: https://sts.windows.net/{tenantid}/

我不确定如何解决此问题,因为此案例中的发行人具有正确的租户ID。

希望有人可以帮我解决这个问题。

1 个答案:

答案 0 :(得分:1)

GitHub上有一个相关的未解决问题:Valid access_token but no identity。原因可能是因为AAD不支持.well-known/openid-configuration的CORS。至少AAD B2C就属于这种情况。我能够通过手动指定发现配置来解决它:

export const aadB2cNoDiscoveryConfig: AuthConfig = {
  'clientId': XXX
  'redirectUri': XXX
  'loginUrl': XXX
  'logoutUrl': XXX
  'scope': 'openid https://mytenant.onmicrosoft.com/myapi/user_impersonation',
  'oidc': true,
  'issuer': 'https://login.microsoftonline.com/XXX/v2.0/',
  'tokenEndpoint': 'https://login.microsoftonline.com/XXX.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_signin',
  'responseType': 'id_token token',
  'clearHashAfterLogin': true,
  'disableAtHashCheck': true,
  'showDebugInformation': true,
  'strictDiscoveryDocumentValidation': false,
  'jwks': {
    'keys': [
      {
        kid: XXX
        nbf: XXX,
        use: XXX
        kty: XXX
        e: XXX
        n: XXX
      }]
  }

注意:我使用过AAD B2C。