-
Notifications
You must be signed in to change notification settings - Fork 30
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
Rework auth to use jwts #2087
Rework auth to use jwts #2087
Conversation
// return next(); | ||
if (req.isAuthenticated()) { | ||
return next(); | ||
const token = req.headers.authorization; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow for both authorization
header and cookie
. Ensure cookie is for the same sub-domain.
…at session validity is checked on Appcomponent init
const jwt = require('jsonwebtoken'); | ||
const expiresIn ='5 minutes'; | ||
const issuer = 'Tangerine'; | ||
const jwtTokenSecret = require('crypto').randomBytes(256).toString('base64'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evansdianga This looks similar to the approach laid out here. Was there another article that you found that talked about this approach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @rjsteinert , most approaches coalesced around using a 256 bit cryptographically secure hashes. There is a link in the PR description which links to a discussion on the hapi.js
repo as they used a similar approach. The discussion there also lists quite a number of links and gives further info on the approach.
Description
Type of Change
Proposed Solution
Use signed JWTs for authentication.
Server cryptographically signs the JWT and send to client. Client stores the JWT and attaches it to every request. The
Angular
client uses theHTTPInterceptor
to attach the token to the request and also to confirm the status of the response of each request.Whenever the server responds with an unauthorized
401
status, the client automatically logs out the user and requires a new session to be initiated through a new login.The JWT signing Options are configurable using environment variables.
We make use of the
jsonwebtoken
library for the server andjwt-decode
library for the client side which enable us decode the encoded JWT to get the response properties.This PR also adds the
rxjs-compat
library to enable userxjs
Warn user when session is about to end due to inactivity. The current default time is to check every 10 minutes and warn the user if the session duration left is less than 15 minutes
The secret key for signing JWTs is generated using the
crypto
module inNodeJS
. Theres a good conversation here dwyl/hapi-auth-jwt2#48 Initially added a string as JWT key for proof of concept. This is now replaced by the string generated by the crypto lib