-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: add support for jwt on api #896
Conversation
add multiple scenarios with configuration file
src/api/web/index.js
Outdated
@@ -15,7 +15,7 @@ const spliceURL = require('../../utils/string').spliceURL; | |||
module.exports = function(config, auth, storage) { | |||
Search.configureStorage(storage); | |||
|
|||
router.use(auth.webUIJWTmiddleware()); | |||
// router.use(auth.webUIJWTmiddleware()); |
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.
reminder: this is odd
src/lib/auth-utils.js
Outdated
|
||
return credentials; | ||
} else { | ||
return; |
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.
No need of return
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.
may be you want it more readable..
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.
Can you replace err
with error
. I'll run it locally later and give one more review.
src/lib/crypto-utils.js
Outdated
return jwt.sign(payload, secretOrPrivateKey, { | ||
notBefore: '1000', // Make sure the time will not rollback :) | ||
...options, | ||
}, (err, token) => { |
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.
arrow ===> function expression
test/lib/server_process.js
Outdated
@@ -76,7 +76,7 @@ export default class VerdaccioProcess implements IServerProcess { | |||
}); | |||
|
|||
this.childFork.on('error', (err) => { | |||
console.log('error process', err); | |||
// console.log('error process', err); |
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.
can we remove it ?
src/lib/auth-utils.js
Outdated
}); | ||
} else { | ||
// i am wiling to use here _.isNil but flow does not like it yet. | ||
if (typeof security.api.jwt !== 'undefined' && |
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.
Destructure...
const {jwt} = security.api;
src/lib/auth-utils.js
Outdated
export function createSessionToken(): CookieSessionToken { | ||
return { | ||
// npmjs.org sets 10h expire | ||
expires: new Date(Date.now() + 10 * 60 * 60 * 1000), |
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.
can we have this as a constant somewhere?
} | ||
|
||
export function getAuthenticatedMessage(user: string): string { | ||
return `you are authenticated as '${user}'`; |
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.
Just check '
this in $user
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.
Yes, it's intended. Don't ask me why :-) ... it was there already and unless I know what it does i cannot remove it.
src/lib/auth-utils.js
Outdated
} | ||
|
||
export function isAESLegacy(security: Security): boolean { | ||
return _.isNil(security.api.legacy) === false && |
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.
Suggestion: destructures..
src/lib/auth-utils.js
Outdated
|
||
return credentials; | ||
} else { | ||
return; |
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.
may be you want it more readable..
src/lib/auth-utils.js
Outdated
if (_.isString(token) && scheme.toUpperCase() === TOKEN_BEARER.toUpperCase()) { | ||
return verifyJWTPayload(token, secret); | ||
} else { | ||
return; |
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.
same here.. return
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.
it was mostly for debugging. Removed
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.
Great! Looks fine 👍
I forgot add this before 😷
in case we want more output
Thanks @priscilawebdev @ayusharma for CR, this is a nice feature. |
* feat: add support for jwt on api * test: add unit test for sign token with jwt add multiple scenarios with configuration file * chore: add JWT verification on middleware * chore: restore headless * chore: restore middleware header validation * refactor: fix login whether user exists * refactor: JWT is signed asynchronously * refactor: better structure and new naming convention * test: add unit test for token signature * test: add unit test for creating user with JWT enabled #168 * docs: add security section jwt * refactor: renable web auth middleware * test(auth): add legacy disabled scenario * chore: update gitignore * chore: add some es6 sugar * feat: enable JWT token signature for new installations * chore: add yaml files to git I forgot add this before 😷 * chore: trace log on auth in case we want more output
* feat: add support for jwt on api * test: add unit test for sign token with jwt add multiple scenarios with configuration file * chore: add JWT verification on middleware * chore: restore headless * chore: restore middleware header validation * refactor: fix login whether user exists * refactor: JWT is signed asynchronously * refactor: better structure and new naming convention * test: add unit test for token signature * test: add unit test for creating user with JWT enabled #168 * docs: add security section jwt * refactor: renable web auth middleware * test(auth): add legacy disabled scenario * chore: update gitignore * chore: add some es6 sugar * feat: enable JWT token signature for new installations * chore: add yaml files to git I forgot add this before 😷 * chore: trace log on auth in case we want more output
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Type: feat
Description:
This PR aims to deprecate AES token generator but without replacing it and allow to use JWT as an alternative on API. (#168 (comment))
Provides customize JWT signature and verification based on
https://github.com/auth0/node-jsonwebtoken#usage
Default Security Config
Legacy
Legacy refers to the default authentification (#168 (comment)) used by
2.x
and3.x
. If you don't define thesecurity
block, legacy is being enabled by default..npmrc
Resolves #168 #729
🆕 enable JWT by default on API.
https://verdaccio.org/blog/2019/04/19/diving-into-jwt-support-for-verdaccio-4