Neeto JWT user login integration#1
Open
VarunSriram99 wants to merge 14 commits into
Open
Conversation
… product with the JWT
95fa8c7 to
a8cc22c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR serves as an example project to integrate JWT-based user login in Neeto. Once a user authenticates against your backend, this flow lets you bounce them into a Neeto product (NeetoCal, NeetoRecord, etc.) without making them sign in again.
Frontend
/api/neeto/:id/neetocal.Backend
Install the package:
yarn add neeto-jwt.Set the following environment variables (see neeto-jwt README):
NEETO_JWT_WORKSPACE: subdomain of your Neeto workspace (e.g.spinkart).NEETO_JWT_PRIVATE_KEY: private key shared by the Neeto team for that workspace.Authenticate the currently logged-in user in your own app.
Use the
neeto-jwtNPM package to mint a short-lived ES256-signed JWT and build the login URL. User scope is the default — noscopeoption needed:Redirect the user to the login URL. NeetoAuth verifies the JWT against the workspace's registered public key, signs the user in, and redirects to the Neeto sub-app.
Important
The private key is the only thing that proves a JWT came from your backend. Never share it, ship it to the browser, or commit it.
Constructor options
emailworkspaceNEETO_JWT_WORKSPACEprivateKeyNEETO_JWT_PRIVATE_KEYscope"user""user") for this flow. Pass"consumer"for the consumer flow instead.Methods
generateJWT()- returns just the signed JWT stringgenerateLoginUrl(redirectUri)- returns the full NeetoAuth login URL with the JWT attached.How NeetoAuth resolves the signing key
The JWT lands at
https://<workspace>.neetoauth.com/users/auth/jwt?...and the auth engine looks up the workspace by the subdomain in the request URL - so the JWT host and your registered workspace must match. If the workspace is not registered, NeetoAuth replies with'<workspace>' workspace is not registered for JWT authentication.Redirect URI rules
For user scope, the
redirectUriyou pass must be a Neeto sub-app - its leading subdomain is stripped by NeetoAuth before redirect. Arbitrary external URLs will not work here.Email pre-existence is required
The email passed in the JWT must already be invited to the workspace. User scope does not auto-create accounts - that's a consumer-scope feature. If the email is unknown, sign-in fails.
Pinned dependency
neeto-jwt@2.0.0(latest as of writing). Earlier versions on the branch (0.0.4,1.0.0,1.1.0) reflect the iteration history and are kept in commit history for reference.Documentation: https://neetoauthhelp.neetokb.com/p/a-f439e89b