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)
我通常会工作,但有时我需要在最终登录的应用程序中多次登录。
预先感谢您的支持!
| 归档时间: |
|
| 查看次数: |
3446 次 |
| 最近记录: |