目前我正在开发一个Angular2应用程序,并希望使用B2C租户进行身份验证 . 它不起作用,因为我收到一个错误:
Invalid issuer in discovery document expected:
设置和配置与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 . 所以我尝试了"old"函数 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;
}
问题在 validateDiscoveryDocument 和 B2C 内
原因是该功能的第一部分:
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/',
提示: 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/**
有人有相同的情况,并找到了解决方法吗?文件中发行人的不同之处是什么?
我也试过以下包:
https://github.com/vip32/angular-oauth2-oidc-b2c
我工作一般,但有时我需要在最终登录的应用程序中多次登录 .
在此先感谢您的支持!
2 回答
我遇到了AzureAD 2.0的类似问题,这就是我设法做的事情 .
据我所知,您可以't relay on discovery document because AzureAD doesn' t允许任何域访问此Json . 我设法进行身份验证,但我需要手动设置所有配置 . 请参阅this issue和this issue . 另外一个接力是重要的,如果你需要从Azure提供这个令牌到你的web API don't send access token 而不是发送 id token . 有关这方面的更多信息,请访问link
我现在不知道如果这有帮助,但它对我有用 .
不幸的是,Azure AD不支持CORS,这就是lib无法加载发现文档的原因 . 您可以手动配置lib(请参阅相关文档;示例还使用备用配置方法演示此示例)或编写支持CORS的自身休息服务并委派给MS的发现 endpoints . 在这种情况下,您需要考虑发现文档指向更多文档,尤其是JWKS . 在这种情况下,这也需要“隧道化” .