Using Cognito Developer Identities on API Gateway JWT Authorizer

0

In the Api Gateway JWT Authorizer, Why it is not possible to use the JWT token generated by getOpenIdTokenForDeveloperIdentity?:

I generate a developer identity token this way:

cognitoIdentity
      .getOpenIdTokenForDeveloperIdentity({
        IdentityPoolId: "us-east-1:43d2cbc6-...",
        // null when you want to create a new identity. An existing authenticated/unauthenticated identity when you want to associate a new login with an existing IdentityId
        // IdentityId: "",
        Logins: {
          mycustomprovider: "user id in my custom provider"
        },
 })

It returns a JWT with a payload and header like this:

{
  "sub": "us-east-1:...",
  "aud": "us-east-1:...",
  "amr": [
    "authenticated",
    "mycustomprovider",
    "mycustomprovider-east-1:...."
  ],
  "iss": "https://cognito-identity.amazonaws.com",
  "exp": 1686581019,
  "iat": 1686577419
}

header:

{
  "kid": "us-east-13",
  "typ": "JWS",
  "alg": "RS512"
}

I configured a JWT Authorizer with

However I get this response header with a error message: www-authenticate: Bearer scope="" error="invalid_token" error_description="unable to decode "n" from RSA public key" status: 401 Unauthorized

What's is wrong with my configuration?

1 個回答
0

I don't think what you are trying to do is possible. The error indicate that the built in JWT authorizer can't read the public key. Normally it tries to fetch the keys from https://<iss>/.well-known/jwks.json however the keys for https://cognito-identity.amazonaws.com is different per region, tryin to fetch https://cognito-identity.amazonaws.com/.well-known/jwks.json result in an access denied.

Instead try and verify using your own custom authorizer using the normal JWT validation steps.

1: Get OpenId config from: https://cognito-identity.amazonaws.com/.well-known/openid-configuration
2: Use the jwks_uri to fetch list of keys (e.g https://cognito-identity.amazonaws.com/.well-known/jwks_uri)
3: Use kid in token to get the correct key
4: Perform validation
profile picture
專家
已回答 1 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南