jonsaw / amazon-cognito-identity-dart

Unofficial Amazon Cognito Identity Provider Dart SDK, to easily add user sign-up and sign-in to your mobile and web apps with AWS.
MIT License
205 stars 93 forks source link

API Gateway / Lambda With Cognito Authorizer - Not Working #77

Closed genjm closed 4 years ago

genjm commented 4 years ago

Afternoon,

I've been following the examples & have managed to get the login working, as well as the basic API Gateway 'GET' call, which is brilliant.

But when I come to add the Cognito Authorizer to the API Gateway, the call fails with 'Unauthenticated' & there's nothing I can see in Cloudwatch that points to what's wrong.

I've attempted to add the Authorization token to the header for the call but it hasn't made any difference:

`final awsSigV4Client = new AwsSigV4Client( credentials.accessKeyId, credentials.secretAccessKey, Common.API_GATEWAY, sessionToken: credentials.sessionToken, region: 'eu-west-2' );

final signedRequest = new SigV4Request(
  awsSigV4Client,
  method: 'GET',
  path: '/playlists',
  headers: {
    'Authorization': credentials.sessionToken
  },
);

try {
  _response = await http.get(signedRequest.url, headers: signedRequest.headers);
} `

Is there anything I'm missing here, or anything I've done wrong, please point me in the right direction!

I am also assuming that once the above is working, the cognito:username will be passed through as part of the claims in the requestContext?

Thanks,

James

genjm commented 4 years ago

My misunderstanding, I've only used the 'Authorization' token in the header before, rather than signed requests, didn't realise it was one or the other!

Thanks for the great package, it's been really straightforward to use so far.