Code Monkey home page Code Monkey logo

Comments (2)

bbilger avatar bbilger commented on May 31, 2024

Hi @spinscale ,
There are multiple ways to accomplish this:

  1. if you just don't want to mange users, Cognito User Pool might be interesting for you. You can protect API endpoints with a Cognito User Pool Authorizer. In case of JRestless >=0.5.0 CognitoUserPoolAuthorizerPrincipal will be set as principal. See the example aws-gateway-security-cognito-authorizer. You, however, cannot integrate any other providers.
  2. what you most likely want to do is to set up a custom authorizer function, like in the example: aws-gateway-security-custom-authorizer. In contrast to the example, however, your authorizer function would verify the twitter/github/amazon token. In case you want to make your life a little easier, use auth0 which integrates with the major providers. You can find an example for such a custom auth0 authorizer here: https://github.com/serverless/examples/blob/master/aws-node-auth0-custom-authorizers-api/handler.js but even without using auth0 it boils down to verifying the JWT token's signature which can be a little tricky: https://developers.google.com/identity/protocols/OpenIDConnect#validatinganidtoken but there are libraries for this, too, I guess. In case of JRestless >=0.5.0 CustomAuthorizerPrincipal will be set as principal.
  3. if and only if you invoke your endpoints through the API Gateway SDK you might want to take a look at Cognito Federated Identites which integrates with all major providers. In case of JRestless >= 0.5.1 CognitoIdentityPrincipal will be set as principal. I am working on an example for this but it's a little tricky and uncommon on Web, and I am very short on time right now.

And last but not least the way AWS implemented those authorizers there is some issue with CORS:
You cannot setup any CORS headers which is an issue if the authorizer fails: https://forum.serverless.com/t/how-to-enable-cors-for-custom-authorizers-aws-api-gateways/1660
In case this is an issue for you, you might want to pull in the authorization into some ContainerRequestFilter (JAX-RS) within your application.

Hope this helps.

from jrestless.

bbilger avatar bbilger commented on May 31, 2024

closing since inactive (please re-open if required)

from jrestless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.