使用 Auth0 的 Node/Hapi 快速入门时出错

Error using Auth0’s Node/Hapi Quickstart

我已经在 https://auth0.com/docs/quickstart/backend/hapi 下载了 Node/Hapi quickstart 和我的 pre-filled 数据。

我能够 运行 节点服务器并访问 /public 端点。当我尝试访问 /private 端点(通过 POSTMAN)时,出现以下错误:

{
  "statusCode": 401,
  "error": "Unauthorized",
  "message": "Missing authentication"
}

为了获得访问令牌,我 POST 使用以下负载向 https://<My Account>.auth0.com/oauth/ro 发出请求:

{
    "client_id":   "<My Client ID>",
    "username":    "<My Username>",
    "password":    "<My Password>",
    "connection":  "Username-Password-Authentication",
    "grant_type":  "password",
    "scope":       "openid name email"
}

其中 returns 包含我的访问令牌的响应:

{
    "id_token": <Id Token>,
    "access_token": <Access Token>,
    "token_type": "bearer"
}

我现在尝试使用我的访问令牌点击传入授权 header 的 /private 端点,如下所示:

GET /private HTTP/1.1
Host: <My Machine Name>:8000
Authorization: Bearer <Access Token>
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 87dd4307-2a1c-b36e-0377-129cf60b676d

其中returns出现以下错误:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Bad HTTP authentication header format"
}

我已经尝试了很多东西,但无法超越这一点。任何帮助将不胜感激。

环境规格:

谢谢, 哲那罗

假设您完全按照问题中描述的方式做事,问题是您需要在调用 [=11] 时传递收到的 id_token =] 端点而不是 access_token.

这在您关注的快速入门的第 4 点中提到:

You can now make requests against your secure API by providing the Authorization header in your requests with a valid JWT id_token.

要更深入地了解整个 Auth0 身份验证系统中使用的不同类型的令牌,您应该阅读 Tokens used by Auth0