Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make handler methods public #66

Closed
vikas-reddy opened this issue Apr 19, 2023 · 0 comments · Fixed by #68
Closed

Make handler methods public #66

vikas-reddy opened this issue Apr 19, 2023 · 0 comments · Fixed by #68

Comments

@vikas-reddy
Copy link
Contributor

vikas-reddy commented Apr 19, 2023

What would you like to be added:

Rename handler methods to make them public. Method names starting with underscore _ are considered private by convention.

Even though these methods are accessible from outside now(Javascript language doesn't understand this _ prefix convention), we think it makes more sense for them to be explicitly public for our use case.

_fetchTokensFromRefreshToken -> fetchTokensFromRefreshToken
_fetchTokensFromCode -> fetchTokensFromCode
_getRedirectToCognitoUserPoolResponse -> getRedirectToCognitoUserPoolResponse

Why is this needed:

We are planning to use this library for our new authentication gateway application. As opposed to the intended use case of this library, which is to use the handle method to place static S3 files behind an authentication gate, we are planning to use the individual handler methods directly in our app. This auth gateway app will be a set of Lambda@Edge handlers that work as an intermediary between React frontend clients and AWS Cognito to do

  1. authentication duties,
  2. exchange code for tokens, and
  3. sending tokens as HttpOnly cookies, which clients can use to communicate with some Amazon internal API's

Handlers

  1. /signIn: Mapped to the existing method _getRedirectToCognitoUserPoolResponse
  2. /parseAuth: Mapped to existing method _fetchTokensFromCode
  3. /refreshToken: Mapped to existing method _fetchTokensFromRefreshToken

In our Cloudfront distribution setup, we'd do something like this (notice no underscore prefixes)

// signIn Lambda@Edge handler
const authenticator = new Authenticator({...})
exports.handler = async (request) => authenticator.getRedirectToCognitoUserPoolResponse(request, redirectUri)

// parseAuth Lambda@Edge handler
const authenticator = new Authenticator({...})
exports.handler = async (request) => authenticator.fetchTokensFromCode(redirectUri, code)

Slack or email me on [email protected] for additional details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants