I want to create a AWS serverless application that uses AWS Cognito for authentication. My starting point is the AWS Serverless Application with Tests (.NET Core) template for C# in Visual Studio 2017. When deployed the template creates some Lambda functions and sets up AWS API Gateway so that I can connect to the Lambda functions via REST requests. This works.
I have created a user pool in AWS Cognito, and a javascript client (a single page application) that lets the user sign in using AWS Cognito. In the javascript client I am able to connect to AWS Cognito and get id, access and refresh tokens as JWT. I can also sent these tokens in an Authorization: Bearer eyblablabla... header to the backend (the AWS serverless application). So the javascript client authentication and AWS Cognito setup appears to work. I have also in AWS API Gateway set up an authorizer that points to the AWS Cognito user pool.
My problem is the following: The backend does not appear to be aware of the authorization header. When examining the request I do not get any claims for the user. I am specifically interested in getting the sub claim so that I can identify the user. Also, I would like the API gateway to automatically send a Unauthorized response for specific methods, but I do not know how to set that up.
As part of the Lambda function signature I get a APIGatewayProxyRequest request object. Apparently the request.RequestContext.Authorizer.Claims should contain the user claims, but the .Authorizer is null.
I am able to get any JWT that I send from the javascript client y reading the request header, so I could parse the token to get user claims. But I figure there must be something wrong with my setup since the .Authorizer does not get populated.
Only suggestions I have found so far involve stuff in a serverless.yml or Swagger template file, neither of which is part of the AWS Serverless Application VS2017 template. Instead I have a serverless.template JSON file, and no obvious way to add authentication / security setup to that file.
My code is so far identical to the AWS Serverless Application template in VS2017.
Any help will be strongly appreciated.