预期发现文档中的无效发行者:Azure B2C的angular-oauth2-oidc

Ale*_*Bla 6 azure oauth-2.0 angular angular-oauth2-oidc

目前,我正在开发Angular2应用,并希望使用B2C租户进行身份验证。它不起作用,因为出现错误:

发现文档中的发行人无效:

设置和配置与https://github.com/manfredsteyer/angular-oauth2-oidc中所述完全相同。

在给定的示例中,使用以下功能:

private configureWithNewConfigApi() {
  this.oauthService.configure(authConfig);
  this.oauthService.tokenValidationHandler = new JwksValidationHandler();
  this.oauthService.loadDiscoveryDocumentAndTryLogin();
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,loadDiscoveryDocumentAndTryLogin对我不起作用,因为对于Azure B2C,我需要添加具有附加参数(策略)的另一个URI。所以我尝试了“旧”功能loadDiscoveryDocument

新的代码如下所示:

private configureWithNewConfigApi() {
  this.oauthService.configure(authConfig);
  this.oauthService.tokenValidationHandler = new JwksValidationHandler();
  //this.oauthService.loadDiscoveryDocumentAndTryLogin();

  const result = this.oauthService.loadDiscoveryDocument(
    'https://login.microsoftonline.com/myportalb2c.onmicrosoft.com/v2.0/.well-known/openid-configuration?p=B2C_1_signin_signup')
    .then(() => {
      console.log('b2c discovery loaded');
      this.oauthService.tryLogin({});
    }).catch(() => {
      console.error('b2c discovery load error');
    });
  }
Run Code Online (Sandbox Code Playgroud)

这是函数的第一部分:

public loadDiscoveryDocument(fullUrl: string = null): Promise<object> {

    return new Promise((resolve, reject) => {

        if (!fullUrl) {
            fullUrl = this.issuer || '';
            if (!fullUrl.endsWith('/')) {
                fullUrl += '/';
            }               
            fullUrl += '.well-known/openid-configuration';
        }
Run Code Online (Sandbox Code Playgroud)

这是github示例中的函数:

public loadDiscoveryDocumentAndTryLogin() {
    return this.loadDiscoveryDocument().then((doc) => {
        return this.tryLogin();
    });
}
Run Code Online (Sandbox Code Playgroud)

loadDiscoveryDocument验证文档:

if (!this.validateDiscoveryDocument(doc)) {
                    this.eventsSubject.next(new OAuthErrorEvent('discovery_document_validation_error', null));
                    reject('discovery_document_validation_error');
                    return;
                }
Run Code Online (Sandbox Code Playgroud)

问题在validateDiscoveryDocument和B2C中

原因是该功能的第一部分:

 if (doc['issuer'] !== this.issuer) {
        console.error(
            'invalid issuer in discovery document',
            'expected: ' + this.issuer,
            'current: ' + doc['issuer']
        );
        return false;
    }
Run Code Online (Sandbox Code Playgroud)

B2C发行人是:

  issuer: 'https://login.microsoftonline.com/myportalb2c.onmicrosoft.com/v2.0/',
Run Code Online (Sandbox Code Playgroud)

提示:myportalb2c不是真正的门户。如果我调用标准URI或使用我的策略(fullUrl),则响应文档中的颁发者与URI中的不同。似乎URI的一部分已被GUID取代

“ issuer”:“ https://login.microsoftonline.com/GUID/v2.0/ ”,“ authorization_endpoint”:“ https://login.microsoftonline.com/myportalb2c.onmicrosoft.com/oauth2/v2.0/ authorize?p = b2c_1_signin_signup “,” token_endpoint“:” https://login.microsoftonline.com/myportalb2c.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_signin_signup “

**https://login.microsoftonline.com/myportalb2c.onmicrosoft.com/v2.0/
!=
https://login.microsoftonline.com/GUID/v2.0/**
Run Code Online (Sandbox Code Playgroud)

有人有同样的情况并找到了解决方法吗?文件中的发行人不同的原因是什么?

我也尝试了以下软件包:

https://github.com/vip32/angular-oauth2-oidc-b2c
Run Code Online (Sandbox Code Playgroud)

我通常会工作,但有时我需要在最终登录的应用程序中多次登录。

预先感谢您的支持!

Ala*_*gar 1

我在使用 AzureAD 2.0 时遇到了类似的问题,这就是我设法做的事情。

据我所知,您无法中继发现文档,因为 AzureAD 不允许任何域访问此 Json。我设法进行身份验证,但我需要手动设置所有配置。参考本期和本期。另一件重要的中继事情是,如果您需要从 Azure 向 Web API 提供此令牌,请不要发送访问令牌,而是发送id 令牌。有关此内容的更多信息请参见此链接

我现在不知道这是否有帮助,但它对我有用。