OAuthService 错误的颁发者错误 (angular-oauth2-oidc)
OAuthService wrong issuer error (angular-oauth2-oidc)
我目前正在尝试在我的 angular 应用程序中实施 Azure 广告身份验证。不幸的是,我 运行 遇到了一些问题。以下代码为我提供了我所期望的访问令牌。要在我的 api 中实现它,我想使用 OpenIDConnect。
export class AppComponent implements OnInit {
title = 'Sign in test';
constructor(private oauthService: OAuthService) {
}
private async ConfigureAuth(): Promise<void> {
this.oauthService.configure({
loginUrl: 'loginUrl',
clientId: 'clientId',
resource: 'resource',
logoutUrl: 'logoutUrl',
redirectUri: window.location.origin + '/',
scope: 'openid',
oidc: false
});
this.oauthService.setStorage(sessionStorage);
}
async ngOnInit() {
await this.ConfigureAuth();
this.oauthService.tryLogin({});
if(!this.oauthService.getAccessToken()) {
await this.oauthService.initImplicitFlow();
}
console.log(this.oauthService.getAccessToken());
}
}
登录仍然有效,因为它给了我访问令牌,但是当我将 oidc
设置为 true
时,它给了我以下错误:
angular-oauth2-oidc.js:1146 Error validating tokens
(anonymous) @ angular-oauth2-oidc.js:1146
Wrong issuer: https://sts.windows.net/{tenantid}/
ERROR Error: Uncaught (in promise): Wrong issuer: https://sts.windows.net/{tenantid}/
我不确定如何解决这个问题,因为本例中的发行人拥有正确的租户 ID。
希望有人能帮我解决这个问题。
GitHub 上有一个相关的未解决问题:Valid access_token but no identity。其原因可能是因为 AAD 不支持 .well-known/openid-configuration
的 CORS。至少 AAD B2C 是这样。我能够通过手动指定发现配置来解决它:
export const aadB2cNoDiscoveryConfig: AuthConfig = {
'clientId': XXX
'redirectUri': XXX
'loginUrl': XXX
'logoutUrl': XXX
'scope': 'openid https://mytenant.onmicrosoft.com/myapi/user_impersonation',
'oidc': true,
'issuer': 'https://login.microsoftonline.com/XXX/v2.0/',
'tokenEndpoint': 'https://login.microsoftonline.com/XXX.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_signin',
'responseType': 'id_token token',
'clearHashAfterLogin': true,
'disableAtHashCheck': true,
'showDebugInformation': true,
'strictDiscoveryDocumentValidation': false,
'jwks': {
'keys': [
{
kid: XXX
nbf: XXX,
use: XXX
kty: XXX
e: XXX
n: XXX
}]
}
注意:我用的是AAD B2C。
我目前正在尝试在我的 angular 应用程序中实施 Azure 广告身份验证。不幸的是,我 运行 遇到了一些问题。以下代码为我提供了我所期望的访问令牌。要在我的 api 中实现它,我想使用 OpenIDConnect。
export class AppComponent implements OnInit {
title = 'Sign in test';
constructor(private oauthService: OAuthService) {
}
private async ConfigureAuth(): Promise<void> {
this.oauthService.configure({
loginUrl: 'loginUrl',
clientId: 'clientId',
resource: 'resource',
logoutUrl: 'logoutUrl',
redirectUri: window.location.origin + '/',
scope: 'openid',
oidc: false
});
this.oauthService.setStorage(sessionStorage);
}
async ngOnInit() {
await this.ConfigureAuth();
this.oauthService.tryLogin({});
if(!this.oauthService.getAccessToken()) {
await this.oauthService.initImplicitFlow();
}
console.log(this.oauthService.getAccessToken());
}
}
登录仍然有效,因为它给了我访问令牌,但是当我将 oidc
设置为 true
时,它给了我以下错误:
angular-oauth2-oidc.js:1146 Error validating tokens
(anonymous) @ angular-oauth2-oidc.js:1146
Wrong issuer: https://sts.windows.net/{tenantid}/
ERROR Error: Uncaught (in promise): Wrong issuer: https://sts.windows.net/{tenantid}/
我不确定如何解决这个问题,因为本例中的发行人拥有正确的租户 ID。
希望有人能帮我解决这个问题。
GitHub 上有一个相关的未解决问题:Valid access_token but no identity。其原因可能是因为 AAD 不支持 .well-known/openid-configuration
的 CORS。至少 AAD B2C 是这样。我能够通过手动指定发现配置来解决它:
export const aadB2cNoDiscoveryConfig: AuthConfig = {
'clientId': XXX
'redirectUri': XXX
'loginUrl': XXX
'logoutUrl': XXX
'scope': 'openid https://mytenant.onmicrosoft.com/myapi/user_impersonation',
'oidc': true,
'issuer': 'https://login.microsoftonline.com/XXX/v2.0/',
'tokenEndpoint': 'https://login.microsoftonline.com/XXX.onmicrosoft.com/oauth2/v2.0/token?p=b2c_1_signin',
'responseType': 'id_token token',
'clearHashAfterLogin': true,
'disableAtHashCheck': true,
'showDebugInformation': true,
'strictDiscoveryDocumentValidation': false,
'jwks': {
'keys': [
{
kid: XXX
nbf: XXX,
use: XXX
kty: XXX
e: XXX
n: XXX
}]
}
注意:我用的是AAD B2C。