examples icon indicating copy to clipboard operation
examples copied to clipboard

How to pass expire token error in custom authoriser for API gateway response

Open dilippatidar123 opened this issue 4 years ago • 8 comments

Hi Team, We are using following configuration. Lambda :-

exports.handler =  async (event, context, callback) => {
    try {
        callback(null,policyData);
        return;
    } catch (err) {
      // Always accepts "Unauthorized".
        callback("Unauthorized");
        return;
    }
};

SAM template :-

ExpiredGatewayResponse:
    Type: 'AWS::ApiGateway::GatewayResponse'
    Properties:
      ResponseParameters:
        gatewayresponse.header.Access-Control-Allow-Origin: "'*'"
        gatewayresponse.header.Access-Control-Allow-Headers: "'*'"
      ResponseType: EXPIRED_TOKEN
      ResponseTemplates:
        application/json: |
          {
            "success":false,
            "message":"Token Expired"
          }
      RestApiId: !Ref ApiGatewayApi
      StatusCode: '401'
  AuthFailureGatewayResponse:
    Type: 'AWS::ApiGateway::GatewayResponse'
    Properties:
      ResponseParameters:
        gatewayresponse.header.Access-Control-Allow-Credentials: "'true'"
        gatewayresponse.header.Access-Control-Allow-Origin: !Ref CorsOriginUrl
        gatewayresponse.header.Access-Control-Allow-Headers: "'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'"
      ResponseType: UNAUTHORIZED
      RestApiId: !Ref ApiGatewayApi
      StatusCode: '401'

In above code its always return unauthorized error. If we pass anything else other then "Unauthorized" in call back then its return the error (message:null).

Please suggest how can we pass any other error response type like expired token form custom authorizer and In SAM it will take the configuration "ExpiredGatewayResponse".

Thanks, Dilip

dilippatidar123 avatar Oct 15 '19 13:10 dilippatidar123

Hi. Any progress with that? I have the same problem

jacobdarrossi avatar Mar 10 '21 00:03 jacobdarrossi

i need it too bump.

feroz-shamsi avatar May 31 '21 04:05 feroz-shamsi

Hi, any one please update on this

tanuj-g avatar Mar 08 '22 11:03 tanuj-g

+1

timreibe avatar Apr 11 '22 10:04 timreibe

+1

GregKapustin avatar Aug 10 '22 19:08 GregKapustin

+1

KashifZaki avatar Aug 31 '22 08:08 KashifZaki

+1

itsmeaksingh avatar Oct 09 '23 07:10 itsmeaksingh

+1

brendo10x avatar Feb 27 '24 19:02 brendo10x