mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Merge pull request #6693 from ErisDS/auth-events
Add user and client authentication events
This commit is contained in:
commit
267ddef9b7
2 changed files with 7 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
||||||
var passport = require('passport'),
|
var passport = require('passport'),
|
||||||
errors = require('../errors'),
|
errors = require('../errors'),
|
||||||
|
events = require('../events'),
|
||||||
labs = require('../utils/labs'),
|
labs = require('../utils/labs'),
|
||||||
i18n = require('../i18n'),
|
i18n = require('../i18n'),
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ auth = {
|
||||||
|
|
||||||
if (!req.body.client_id || !req.body.client_secret) {
|
if (!req.body.client_id || !req.body.client_secret) {
|
||||||
errors.logError(
|
errors.logError(
|
||||||
i18n.t('errors.middleware.auth.clientAuthenticaionFailed'),
|
i18n.t('errors.middleware.auth.clientAuthenticationFailed'),
|
||||||
i18n.t('errors.middleware.auth.clientCredentialsNotProvided'),
|
i18n.t('errors.middleware.auth.clientCredentialsNotProvided'),
|
||||||
i18n.t('errors.middleware.auth.forInformationRead', {url: 'http://api.ghost.org/docs/client-authentication'})
|
i18n.t('errors.middleware.auth.forInformationRead', {url: 'http://api.ghost.org/docs/client-authentication'})
|
||||||
);
|
);
|
||||||
|
@ -66,7 +67,7 @@ auth = {
|
||||||
|
|
||||||
if (!client || client.type !== 'ua') {
|
if (!client || client.type !== 'ua') {
|
||||||
errors.logError(
|
errors.logError(
|
||||||
i18n.t('errors.middleware.auth.clientAuthenticaionFailed'),
|
i18n.t('errors.middleware.auth.clientAuthenticationFailed'),
|
||||||
i18n.t('errors.middleware.auth.clientCredentialsNotValid'),
|
i18n.t('errors.middleware.auth.clientCredentialsNotValid'),
|
||||||
i18n.t('errors.middleware.auth.forInformationRead', {url: 'http://api.ghost.org/docs/client-authentication'})
|
i18n.t('errors.middleware.auth.forInformationRead', {url: 'http://api.ghost.org/docs/client-authentication'})
|
||||||
);
|
);
|
||||||
|
@ -75,6 +76,7 @@ auth = {
|
||||||
|
|
||||||
req.client = client;
|
req.client = client;
|
||||||
|
|
||||||
|
events.emit('client.authenticated', client);
|
||||||
return next(null, client);
|
return next(null, client);
|
||||||
}
|
}
|
||||||
)(req, res, next);
|
)(req, res, next);
|
||||||
|
@ -91,6 +93,8 @@ auth = {
|
||||||
if (user) {
|
if (user) {
|
||||||
req.authInfo = info;
|
req.authInfo = info;
|
||||||
req.user = user;
|
req.user = user;
|
||||||
|
|
||||||
|
events.emit('user.authenticated', user);
|
||||||
return next(null, user, info);
|
return next(null, user, info);
|
||||||
} else if (isBearerAutorizationHeader(req)) {
|
} else if (isBearerAutorizationHeader(req)) {
|
||||||
return errors.handleAPIError(new errors.UnauthorizedError(i18n.t('errors.middleware.auth.accessDenied')), req, res, next);
|
return errors.handleAPIError(new errors.UnauthorizedError(i18n.t('errors.middleware.auth.accessDenied')), req, res, next);
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
},
|
},
|
||||||
"middleware": {
|
"middleware": {
|
||||||
"auth": {
|
"auth": {
|
||||||
"clientAuthenticaionFailed": "Client Authentication Failed",
|
"clientAuthenticationFailed": "Client Authentication Failed",
|
||||||
"clientCredentialsNotProvided": "Client credentials were not provided",
|
"clientCredentialsNotProvided": "Client credentials were not provided",
|
||||||
"clientCredentialsNotValid": "Client credentials were not valid",
|
"clientCredentialsNotValid": "Client credentials were not valid",
|
||||||
"forInformationRead": "For information on how to fix this, please read {url}.",
|
"forInformationRead": "For information on how to fix this, please read {url}.",
|
||||||
|
|
Loading…
Add table
Reference in a new issue