By using AWS re:Post, you agree to the Terms of Use

API Gateway - How to accept Authorization with Bearer keyword - HTTP API


API Gateway HTTP usign Cognito requires JWT token to be included in Authorization Header. This is a problem when testing against Swagger Editor, which includes "Bearer" keyboard in Authorization Header. Is there a way to configure API Gateway to accept JWT with Bearer keyword?

OpenAPI Schema:

            type: oauth2
                  aws.cognito.signin.user.admin: Gives you access to all the User Pool APIs that can be accessed using access tokens alone
                  email: Grants access to the email and email_verified claims. This scope can only be requested with the openid scope.
                  openid: Returns all user attributes in the ID token that are readable by the client. The ID token is not returned if the openid scope is not requested by the client.
                  phone: Grants access to the phone_number and phone_number_verified claims. This scope can only be requested with the openid scope.
                  profile: Grants access to all user attributes that are readable by the client. This scope can only be requested with the openid scope.
              identitySource: "$request.header.Authorization"
                - "xxxxxxxx"
                issuer: ""
              type: "jwt"
  - AwsOAuth2: []

Generates following curl request in OpenAPI Swagger Editor:

curl -X 'GET' \
  '' \
  -H 'accept: application/json' \
  -H 'Authorization: Bearer eyJraWQiOiJ1aVcwc3Exxxxxxxxxxxx'

Problem is, that this gets rejected by API Gateway HTTP when integrating with Cognito. It requires header like this (without Bearer):

  -H 'Authorization: eyJraWQiOiJ1aVcwc3Exxxxxxxxxxxx'
1 Answer
Accepted Answer

Assuming you are using the HTTP API with a JWT Authorizer, that should not be an issue. Please take a look at this document -

If you look at this section

Authorizing API requests API Gateway uses the following general workflow to authorize requests to routes that are configured to use a JWT authorizer.

Check the identitySource for a token. The identitySource can include only the token, or the token prefixed with Bearer .

So adding the token pre-fixed with Bearer is acceptable. The problem could be somewhere else.

profile picture
answered 12 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions