AWS API 网关身份验证错误 IncompleteSignatureException using JWT with Auth0

AWS API Gateway authentication error IncompleteSignatureException using JWT with Auth0

我在哪里

我目前正在为 AWS API 网关设置 Auth0 委托身份验证。我已经按照下面的文档和教程进行操作,除了我有一个应用程序而不是他们的示例应用程序:

https://auth0.com/docs/quickstart/spa/angular2/aws

https://auth0.com/blog/2015/11/10/introducing-angular2-jwt-a-library-for-angular2-authentication/

https://auth0.com/docs/client-platforms/angular2

https://auth0.com/docs/integrations/aws-api-gateway/part-2

什么在起作用

什么不起作用

身份验证 header 是

Authentication: Bearer edJ0e...[I've truncated for brevity]

AWS 会期待使用键值对的不同类型的身份验证吗?如何告诉 AWS API 网关它应该寻找 JWT?

我猜您已经为 API 网关端点启用了 AWS_IAM 身份验证。如果您不打算使用它,则需要禁用它。如果您计划在 JWT 之外使用 AWS_IAM 身份验证,那么您将必须使用不同的字段发送 JWT 令牌。

来自您链接的 Auth0 教程的 part 5

The final step is to pass the JWT to the method from the browser client. The standard method is with an Authorization header as a bearer token, and you can use this method if you turn off IAM authorization and rely solely upon the OpenID token for authorization (you will also need to map the Authorization header into the event data passed to the AWS Lambda function). If you are using IAM, then the AWS API Gateway uses the Authorization header to contain the signature of the message, and you will break the authentication by inserting the JWT into this header. You could either add a custom header for the JWT, or put it into the body of the message. If you choose to use a custom header, you'll also need to do some mapping for the Integration Request of the POST method

根据错误消息,您似乎已经为 AWS_IAM 身份验证配置了 API。这需要使用 AWS Signature Version 4.

签署您的请求

为了执行 API 网关功能,您需要做 3 件事中的 1 件事:

  1. auth0 example 中所述,通过 IAM/STS 获取 AWS 凭据,并使用这些凭据签署您的请求。
  2. 如教程 , follow the instructions in step 5 中所述,auth0 并禁用 AWS_IAM 身份验证并在您的 Lambda 中进行验证。
  3. 切换为使用 a custom authorizer 直接在 API 网关层验证 JWT。这将要求您使用 Auth0 提供的代码来验证令牌,然后构建您自己的授权结果。

(代题作者发表).

更新

Mark B 和 Bob Kinney 都是正确的。我所做的(你可能也有)是在我发布在这个问题顶部的各种 Auth0 链接中跳来跳去,并尝试使用他们的 angular2-jwt 库(带有 AuthHttp 组件)使教程适应 Angular2,同时遵循以及他们使用 AWS API 网关设置 Auth0 的 5 部分示例。 AuthHttp 组件会自动将 JWT Bearer 令牌放入 "Authentication" HTTP header 中,这与受 IAM 授权保护的 AWS API 网关调用不兼容。正如这些男士向我展示的那样,这在本教程的第 5 部分中进行了解释。如果你只完成了第 4 部分并且它没有工作希望这能像我一样回答你的问题。

更新 2

Auth0 Angular2 教程已更新以反映 Angular2 rc 1。https://auth0.com/blog/2015/05/14/creating-your-first-real-world-angular-2-app-from-authentication-to-calling-an-api-and-everything-in-between/