【发布时间】:2018-04-11 13:48:40
【问题描述】:
目前我正在开发一个 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;
}
问题在于 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 替换了
"发行人": "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
我工作一般,但有时我需要在最终登录的应用程序中登录几次。
提前感谢您的支持!
【问题讨论】:
标签: angular azure oauth-2.0 angular-oauth2-oidc