【问题标题】:angular-oauth2-oidc is not setting access_tokenangular-oauth2-oidc 未设置 access_token
【发布时间】:2018-06-24 08:23:42
【问题描述】:

我按照 angular-oauth2-oidc 库的入门指南进行操作,但它存储的唯一内容是 nonce 值,access_token 不会出现在任何地方。

这是我对AuthConfig 的配置。

export const AUTHCONFIG: AuthConfig = {
    loginUrl: 'https://login.microsoftonline.com/xxxxxxxx/oauth2/authorize',
    redirectUri: window.location.origin + '/', //localhost:4200/
    clientId: 'the id of my angular app registered in azure',
    resource: 'the id of my web api in nodejs also registered',
    oidc: true,
    requireHttps: false // this is for testing in localhost
};

我的app.component.ts 有以下内容:

export class AppComponent {
     constructor(private oauthService: OAuthService) {this.loadConfig()}
     loadConfig(): void {
         this.ouathService.configure(AUTHCONFIG);
         this.ouathService.tokenValidationHandler
                          = new JwksValidationHandler();
         this.ouathService.token.setStorage(localStorage);
     }
}

在我的login.component.ts 我有:

export class LoginComponent {
    constructor(private oauthService: OAuthService) {}
    login(): void { this.oauthService.initImplicitFlow();}
}

用户被重定向到这里后,我可以在 url 中看到 access_token 等参数。

但是当我去 localStorage 时,我唯一能看到的是nonce 及其值,而不是access_token。我已经尝试在控制台中打印它并收到null

这是我返回的网址:http://localhost:4200/#access_token=thetoken&etcparams

【问题讨论】:

  • 您确定该库与 Azure AD 兼容吗?
  • @juunas 是的,我看到了这个教程youtube.com/watch?v=RSqREkxe2z0。我已经解决了我的问题,现在我可以看到 access_token,我有一个新错误,它说我有一个错误的颁发者,所以它无法验证令牌。我将 issuer 属性设置为 login.microsoftonline.com,但它一直说这是一个错误的 issuer。
  • 错误在哪里,您是如何解决的?从登录页面返回后,我也无法访问令牌 - 即使它被设置为 url 中的参数。
  • @Entertain 错误是我没有在我的 AuthConfig 中设置 issuer 和 jwks 属性,这显然是正常工作所必需的,一旦你填写了这些道具,它应该可以正常工作:)。
  • @Entertain 对你有用吗?

标签: angular oauth-2.0 azure-active-directory openid angular-oauth2-oidc


【解决方案1】:

@Otto Cheley 你不需要添加 JWK 验证器。

    export class AppComponent {
     constructor(private oauthService: OAuthService) {this.loadConfig()}
     loadConfig(): void {
         this.ouathService.configure(AUTHCONFIG);
        // this.ouathService.tokenValidationHandler = new JwksValidationHandler();
         this.ouathService.token.setStorage(localStorage);
     }
    }

尝试评论 tokenValidator

【讨论】:

    猜你喜欢
    • 2018-06-30
    • 2022-12-22
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 2021-07-02
    • 2019-08-02
    • 2022-07-07
    • 2020-06-06
    相关资源
    最近更新 更多