- General info
- Configure Auth
- Auth via Apple
- Auth via Facebook
- Auth via Google
- Auth via Twitter
- Logout
By default boilerplate used sign in and sign up via email and password.
sequenceDiagram
participant A as Fronted App (Web, Mobile, Desktop)
participant B as Backend App
A->>B: 1. Sign up via email and password
A->>B: 2. Sign in via email and password
B->>A: 3. Get a JWT token
A->>B: 4. Make any requests using a JWT token
auth-email.mp4
Also you can sign up via another external services or social networks like Apple, Facebook, Google, and Twitter.
sequenceDiagram
participant B as External Auth Services (Apple, Google, etc)
participant A as Fronted App (Web, Mobile, Desktop)
participant C as Backend App
A->>B: 1. Sign in through an external service
B->>A: 2. Get Access Token
A->>C: 3. Send Access Token to auth endpoint
C->>A: 4. Get a JWT token
A->>C: 5. Make any requests using a JWT token
For auth with external services or social networks you need:
-
Sign in through an external service and get access token(s).
-
Call one of endpoints with access token received in frontend app on 1-st step and get JWT token from the backend app.
POST /api/v1/auth/facebook/login POST /api/v1/auth/google/login POST /api/v1/auth/twitter/login POST /api/v1/auth/apple/login
-
Make any requests using a JWT token
-
Generate secret keys for
access token
andrefresh token
:node -e "console.log('\nAUTH_JWT_SECRET=' + require('crypto').randomBytes(256).toString('base64') + '\nAUTH_REFRESH_SECRET=' + require('crypto').randomBytes(256).toString('base64'));"
-
Go to
/.env
and replaceAUTH_JWT_SECRET
andAUTH_REFRESH_SECRET
with output from step 1.AUTH_JWT_SECRET=HERE_SECRET_KEY_FROM_STEP_1 AUTH_REFRESH_SECRET=HERE_SECRET_KEY_FROM_STEP_1
-
Set up your service on Apple
-
Change
APPLE_APP_AUDIENCE
in.env
APPLE_APP_AUDIENCE=["com.company", "com.company.web"]
-
Set up your service on Facebook
-
Change
FACEBOOK_APP_ID
andFACEBOOK_APP_SECRET
in.env
FACEBOOK_APP_ID=abc FACEBOOK_APP_SECRET=abc
-
Set up your service on Google
-
Change
GOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
in.env
GOOGLE_CLIENT_ID=abc GOOGLE_CLIENT_SECRET=abc
-
Set up your service on Twitter
-
Change
TWITTER_CONSUMER_KEY
andTWITTER_CONSUMER_SECRET
in.env
TWITTER_CONSUMER_KEY=abc TWITTER_CONSUMER_SECRET=abc
-
Call following endpoint:
POST /api/v1/auth/logout
-
Remove
access token
andrefresh token
from your client app (cookies, localStorage, etc).
Previous: Working with database
Next: Serialization