Search code examples
amazon-web-servicesaws-api-gatewayopenid-connectonelogin

AWS API Gateway Authentication with OneLogin


I've been exploring OneLogin and I think I have a basic understanding of how to use it; I was successful at configuring the Node+Passport sample application to authenticate with OneLogin and I understand the code.

I want to try it with AWS API Gateway. I've got an API already defined in AWS. On a high level I know I need to configure an Authorizer in AWS for OneLogin and that there is going to be some bit of information that I will need to pass in a header when I make my calls to the AWS Api Gateway (I assume a Bearer token that I get from authenticating with OneLogin before I interact with AWS, but I don't know).

Can someone give me a description of what I need to do? The most recent question that I see here on the topic was posted in 2016 back when the answer was "You can't do that." That answer has changed in the past 4 years. The OneLogin documentation says it can be done, but I have found not information on how to do it.


Solution

  • GENERAL PATTERN

    The role of an authorizer function is to perform the following actions:

    • Validate access token
    • Optionally collect additional claims
    • Cache the claims for subsequent requests with the same token
    • Provide claims to business logic

    In fact this is a general pattern that can be used anywhere, as referenced in my blog post.

    TOKEN VALIDATION

    AWS SPECIFICS

    Since you are using OneLogin you will need to write some custom code. Your lambda authorizer will need to do standard OAuth 2.0 work, then return an AWS policy document. Some resources of mine may help you to understand how this works:

    PAIN POINTS

    The AWS plumbing is a bit painful, and it is possible you are using some different technology choices to me - I am using the Serverless Framework.

    Hopefully though, this gives you something to run locally and compare against. Happy to answer any follow up questions ...