Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
ghost-express-auth
Advanced tools
npm install ghost-express-auth --save
This module is built on top of express and can be imported as a means to handle user authentication in your application. Pass in a configuration file and your DB, and the module defines routes to handle login, registration, password reset and role management.
There are also various exposed middleware objects that can be used for managing user access and permissions.
const GhostExpressAuth = require('ghost-express-auth');
const GhostAuth = new GhostExpressAuth(config, Db);
const AuthRouter = GhostAuth.AuthRouter;
app.use('/auth', AuthRouter);
The following methods are available:
Endpoint | Description |
---|---|
GET /authorized | Get authorization |
GET /request-password-reset/:email | Request an email with a link to reset password |
GET /verify-reset-token/:token | Verify that a reset token exists and has not been used |
POST /login | Login |
POST /register/:role | Register |
POST /reset-password | Reset a password |
$http({method: 'GET', url: "/auth/authorized"})
.then(response => ...)
.catch(response => ...)
{
"profile": {
"id": 1,
"name": "Justin Tucker"
},
"authorization": {
"role": "user"
},
"status": "ACTIVE"
}
### `GET /request-password-reset/:email`
const requestPasswordReset = (email) => {
return $http({method: 'GET', url: '/auth/request-password-reset/' + email})
.then(response => ...)
.catch(response => ...)
}
200
success, email sent
4**
email address is not in system
5**
server error
const verifyResetToken = (tokenId) => {
return $http({method: 'GET', url: '/auth/verify-reset-token/' + tokenId})
.then(response => ...)
.catch(response => ...)
}
200
token is valid and unused
4**
token is expired (over 24 hours old) or already used
5**
server error
const login = (email, password) => {
$http({method: 'POST', url: "/auth/login", data: {email: email, password: password} })
.then(response => ...)
.catch(response => ...)
}
Note: tkn is returned as an encoded JWT string
{
"tkn": {
"user": 1,
"expires": "1/1/2017",
"role": "admin"
},
"role": "admin"
}
### `POST /register/:role`
const register = (email, password, role) => {
$http({method: 'POST', url: "/auth/register/" + role, data: {email: email, password: password} })
.then(response => ...)
.catch(response => ...)
}
Note: tkn is returned as an encoded JWT string
{
"tkn": {
"user": 1,
"expires": "1/1/2017",
"role": "admin"
},
"role": "admin"
}
### `POST /reset-password`
Note: the server will validate that the provided reset token ID is linked to the provided email address.
/**
* @param {Object} data
* @param {String} data.email
* @param {String} data.password
* @param {String} data.token
* @returns {Promise}
*/
const resetPassword = (data) => {
$http({method: 'POST', url: "/auth/reset-password", data: data })
.then(response => ...)
.catch(response => ...)
}
200
token is valid and unused
4**
token is expired (over 24 hours old), already used, or not linked to provided email address
5**
server error
authSecret
: Secret key used for Bearer authorization tokensemail
: Configure email settingsenabled
: [BOOLEAN] if enabled, module will attempt to use email functionality,baseUrl
: the base url of your website, to be used in generating urls sent as substitutions in emails,processor
: ['mailchimp'|'sendgrid'] *currently only supporting mailchimpmailchimp
:
defaults
: email defaults
fromEmail
fromName
replyTo
templates
: the various available templates for emails. each has 2 properties templateName
and subject
passwordResetNotification
: sent to user upon successful password resetpasswordResetRequest
: sent to user upon requesting a password reset,welcome
: sent to user upon registeringroles
: Configure user role settings
{roleObject}
An object whose key is the name of the user role (e.g. 'user', 'admin', 'guest').
notifyAdminsOnRegistration
: Notifying all users with 'admin' role when a user with this role registers. The following variables will be available in the template: userName, userEmail, registeredAt, userRole
enabled
[BOOLEAN] whether or not to implement notification logictemplateName
[String] the template of the email to send adminssubject
[String]{
"authSecret": "super$ecure",
"email": {
"enabled": true,
"baseUrl": "http://192.168.99.100:4000",
"processor": "mailchimp",
"mailchimp": {
"defaults": {
"fromEmail": "info@yourwebsite.com",
"fromName": "The Email Guy",
"replyTo": "info@yourwebsite.com"
},
"secretKey": "[your mailchimp secret key]",
"mandrill": "[your mandrill key]"
},
"templates": {
"passwordResetNotification": {
"templateName": "password_reset_notification",
"subject": "Password Reset Notification"
},
"passwordResetRequest" : {
"templateName": "password_reset_request",
"subject": "Password Reset Request"
},
"welcome": {
"templateName": "welcome_user",
"subject": "Welcome to Ghost Creative!"
}
}
},
"roles": {
"user": {
"level": 1,
"notifyAdminsOnRegistration": {
"enabled": true,
"templateName": "new_user_notification",
"subject": "Ghost Creative Has a New Patient!"
},
"secret": "IMALITTLETEAPOT",
"welcomeEmail": {
"templateName": "welcome_user",
"subject": "Welcome to Ghost Creative!"
}
},
"admin": {
"level": 2,
"notifyAdminsOnRegistration": {
"enabled": true,
"templateName": "new_admin_notification",
"subject": "New Ghost Creative Admin Registration"
},
"secret": "admins",
"welcomeEmail": {
"templateName": "welcome_admin",
"subject": "Welcome to Ghost Creative!"
}
}
}
}
FAQs
nodejs client to handle authorization for express apps
The npm package ghost-express-auth receives a total of 5 weekly downloads. As such, ghost-express-auth popularity was classified as not popular.
We found that ghost-express-auth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.