代码之家  ›  专栏  ›  技术社区  ›  Jeroen

使用angular-oauth2-oidc库从Auth0获取完全访问令牌

  •  -1
  • Jeroen  · 技术社区  · 8 年前

    the angular-oauth2-oidc 库设置为与Auth0一起使用。但是,Auth0一直给我发送一个非常短的访问令牌,例如。 mSNhEfdDHK6t-kT5QweRtgec-FPGAsdfEw9 ,而不是完整的JWT令牌。以下是如何重现这一问题的:

    1. 在Auth0中创建为隐式流设置的SPA应用程序。
    2. angular-oauth2-oidc 或克隆 my sample repo .
    3. export const authConfig: AuthConfig = {
        issuer: 'https://your-tenant-name.eu.auth0.com/',
        clientId: 'your-spa-client-id-here',
        redirectUri: window.location.origin + '/index.html',
        scope: 'openid profile email',
      };
      
    4. 触发 initImplicitFlow() 通过单击应用程序上的“登录”按钮进行调用。

    当您这样做时:

    • 应为:两个令牌都是完整的JWT令牌。

    this thread on the Auth0 community forums sope 就像我一样,打电话 /authorize 等等)。然而,在那条线的下面,它提到 audience 打电话时 是解决办法 ,无论如何,这似乎是件好事。

    观众 ? 上没有这样的财产 the AuthConfig type 设置它,并查看 location.href 所以那里也没有拦截。

    1 回复  |  直到 8 年前
        1
  •  3
  •   Jeroen    8 年前

    你就快到了。尽管拥有 audience 作为 AuthConfig the customQueryParams 为此:

    export const authConfig: AuthConfig = {
      issuer: 'https://your-tenant-name.eu.auth0.com/',
      clientId: 'your-spa-client-id-here',
      redirectUri: window.location.origin + '/index.html',
      scope: 'openid profile email',
      customQueryParams: {
        audience: 'https://your-api-audience-id.example.com',
      },
    };
    

    观众 是您在Auth0中配置的标识符。下面是管理界面的截图:

    Identifier is the Audience parameter

    推荐文章