I am creating a server less REST API using AWS API Gateway and AWS Lambda. While the end points have been created and linked with the corresponding Lambda functions, next step is to add authentication layer to authenticate users via email and password. From what I could understand from the documentation, API Gateway methods can support either API Key based access or IAM based access. But I could not understand how to securely implement the authentication using API keys.
Will I have to create a server for doing the authentication and managing the users ? Is there any way this can be a complete server less end to end application ? Any resources for pointing in the right direction will be highly appreciated. I am looking at this document at the moment
Authenticate API requests using basic authentication with your email address and password, with your email address and an API token, or with an OAuth access token. All methods of authentication set the authorization header differently. Credentials sent in the payload or URL are not processed.
Making an authenticated request to an API Gateway API. To make an authenticated request, the calling service sends a JWT signed by the service account that you specified in the API config. The calling service must: Create a JWT and sign it with the service account's private key.
To allow an API developer to create and manage an API in API Gateway, you must create IAM permissions policies that allow a specified API developer to create, update, deploy, view, or delete required API entities.
A recent announcement was API Gateway Custom Authorizers: http://docs.aws.amazon.com/apigateway/latest/developerguide/use-custom-authorizer.html
"you can control access to your APIs using bearer token authentication strategies, such as OAuth or SAML. To do so, you provide and configure a custom authorizer, a Lambda function you own, for API Gateway to use to authorize the client requests for the configured APIs"
Another good resource which I think was written before the Custom Authorizer release: https://auth0.com/docs/integrations/aws-api-gateway/part-2
AWS API Gateway can be Authenticated using API Keys as well. Follow the below Steps :-
After then when the API Gateway is called the API key needs to be passed as a Header.
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(new MediaType[]{MediaType.APPLICATION_JSON}));
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("x-api-key", apiKey);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With