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

如何获得正确的Auth0承载令牌?

  •  4
  • MoeSattler  · 技术社区  · 10 年前

    我想为我的节点获取Auth0承载令牌。js应用程序。

    我这样做得到了不记名代币:

    curl https://myproject.eu.auth0.com/oauth/token --data "client_id=ID&client_secret=SECRET&type=web_server&grant_type=client_credentials"

    这让我回想起:

    {
      "access_token": *BEARER TOKEN*,
      "token_type": "Bearer"
    }
    

    但是,如果我在Auth头中使用邮递员的令牌,它会告诉我: Invalid token 。那么我该如何获得正确的无记名令牌呢?

    我的服务器看起来像这样:

    const koa = require('koa');
    const route = require('koa-route');
    const jwt = require('koa-jwt');
    const testRoute = require('./testRoute');
    
    const app = koa();
    //Copy pasted those values from my auth0 dashboard
    const authentication = jwt({
      secret: new Buffer(*CLIENT_SECRET*, 'base64'),
      audience: *YOUR_CLIENT_ID*
    });
    app.use(authentication);
    app.use(route.get('/test', testRoute));
    app.listen(3000);
    

    我按照本指南进行了设置: https://auth0.com/docs/quickstart/backend/nodejs/ .

    1 回复  |  直到 10 年前
        1
  •  8
  •   Rodrigo López Dato    10 年前

    这个 access_token 是一个不透明的令牌,而不是应用程序期望的JWT。如果您使用 scope=openid 打电话给 /oauth/token 你会得到一个 id_token 这也是API应该接受的JWT。

    您可以阅读更多关于 scope 参数在Auth0的上下文中工作: https://auth0.com/docs/scopes

    推荐文章