应为发现文档中的无效颁发者:angular-oauth2-oidc与Azure B2C



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

应为发现文档中的无效颁发者:

设置和配置与https://github.com/manfredsteyer/angular-oauth2-oidc描述。

在给定的示例中,使用了以下函数:

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

不幸的是,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');
});
}

这是功能的第一部分:

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

以下是github示例中的函数:

public loadDiscoveryDocumentAndTryLogin() {
return this.loadDiscoveryDocument().then((doc) => {
return this.tryLogin();
});
}

loadDiscoveryDocument验证文档:

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

问题在验证DiscoveryDocumentB2C

原因是功能的第一部分:

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

B2C发卡机构是:

issuer: 'https://login.microsoftonline.com/myportalb2c.onmicrosoft.com/v2.0/',

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

"发行人":"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/**

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

我还尝试了以下包:

https://github.com/vip32/angular-oauth2-oidc-b2c

我通常工作,但有时我需要在应用程序中登录几次,最后才能登录。

提前感谢您的支持!

我在AzureAD 2.0中遇到了模拟程序问题,下面是我要做的。

据我所知,您无法转发发现文档,因为AzureAD不允许任何域访问此Json。我设法进行了身份验证,但我需要手动设置所有配置。请参阅本期和本期。还有一件很重要的事情,如果您需要从Azure向web API提供此令牌,请不要发送访问令牌,而是发送

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

不幸的是,Azure AD不支持CORS,这就是lib无法加载发现文档的原因。您可以手动配置lib(请参阅文档;该示例还用另一种配置方法演示了这一点),或者编写一个自己的rest服务,支持CORS并委托给MS的发现端点。在这种情况下,您需要考虑发现文档指向其他文档,尤其是JWKS。在这种情况下,这也需要"隧道化"。


我遇到了同样的问题,但当我将strictDiscoveryDocumentValidation作为false通过时,它解决了我的问题

在AuthConfig中,请设置

strictDiscoveryDocumentValidation: false

最新更新