fix: linted library.js
This commit is contained in:
parent
8c57b5c105
commit
9f6ab199de
69
library.js
69
library.js
@ -1,6 +1,6 @@
|
|||||||
(function(module) {
|
'use strict';
|
||||||
"use strict";
|
|
||||||
|
|
||||||
|
(function (module) {
|
||||||
/*
|
/*
|
||||||
Welcome to the SSO OAuth plugin! If you're inspecting this code, you're probably looking to
|
Welcome to the SSO OAuth plugin! If you're inspecting this code, you're probably looking to
|
||||||
hook up NodeBB with your existing OAuth endpoint.
|
hook up NodeBB with your existing OAuth endpoint.
|
||||||
@ -16,18 +16,17 @@
|
|||||||
Step 4: If all goes well, you'll be able to login/register via your OAuth endpoint credentials.
|
Step 4: If all goes well, you'll be able to login/register via your OAuth endpoint credentials.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var User = module.parent.require('./user'),
|
const User = require.main.require('./src/user');
|
||||||
Groups = module.parent.require('./groups'),
|
const Groups = require.main.require('./src/groups');
|
||||||
meta = module.parent.require('./meta'),
|
const db = require.main.require('./src/database');
|
||||||
db = module.parent.require('../src/database'),
|
const authenticationController = require.main.require('./src/controllers/authentication');
|
||||||
passport = module.parent.require('passport'),
|
|
||||||
fs = module.parent.require('fs'),
|
const async = require('async');
|
||||||
path = module.parent.require('path'),
|
|
||||||
nconf = module.parent.require('nconf'),
|
const passport = module.parent.require('passport');
|
||||||
winston = module.parent.require('winston'),
|
const nconf = module.parent.require('nconf');
|
||||||
async = module.parent.require('async');
|
const winston = module.parent.require('winston');
|
||||||
|
|
||||||
var authenticationController = module.parent.require('./controllers/authentication');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* REMEMBER
|
* REMEMBER
|
||||||
@ -64,10 +63,15 @@
|
|||||||
clientID: nconf.get('oauth:id'), // don't change this line
|
clientID: nconf.get('oauth:id'), // don't change this line
|
||||||
clientSecret: nconf.get('oauth:secret'), // don't change this line
|
clientSecret: nconf.get('oauth:secret'), // don't change this line
|
||||||
},
|
},
|
||||||
userRoute: '' // This is the address to your app's "user profile" API endpoint (expects JSON)
|
userRoute: '', // This is the address to your app's "user profile" API endpoint (expects JSON)
|
||||||
}),
|
});
|
||||||
configOk = false,
|
|
||||||
OAuth = {}, passportOAuth, opts;
|
|
||||||
|
var configOk = false;
|
||||||
|
|
||||||
|
|
||||||
|
var OAuth = {}; var passportOAuth; var
|
||||||
|
opts;
|
||||||
|
|
||||||
if (!constants.name) {
|
if (!constants.name) {
|
||||||
winston.error('[sso-oauth] Please specify a name for your OAuth provider (library.js:32)');
|
winston.error('[sso-oauth] Please specify a name for your OAuth provider (library.js:32)');
|
||||||
@ -89,8 +93,10 @@
|
|||||||
opts.callbackURL = nconf.get('url') + '/auth/' + constants.name + '/callback';
|
opts.callbackURL = nconf.get('url') + '/auth/' + constants.name + '/callback';
|
||||||
|
|
||||||
passportOAuth.Strategy.prototype.userProfile = function (token, secret, params, done) {
|
passportOAuth.Strategy.prototype.userProfile = function (token, secret, params, done) {
|
||||||
this._oauth.get(constants.userRoute, token, secret, function(err, body, res) {
|
this._oauth.get(constants.userRoute, token, secret, function (err, body/* , res */) {
|
||||||
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var json = JSON.parse(body);
|
var json = JSON.parse(body);
|
||||||
@ -111,8 +117,10 @@
|
|||||||
opts.callbackURL = nconf.get('url') + '/auth/' + constants.name + '/callback';
|
opts.callbackURL = nconf.get('url') + '/auth/' + constants.name + '/callback';
|
||||||
|
|
||||||
passportOAuth.Strategy.prototype.userProfile = function (accessToken, done) {
|
passportOAuth.Strategy.prototype.userProfile = function (accessToken, done) {
|
||||||
this._oauth2.get(constants.userRoute, accessToken, function(err, body, res) {
|
this._oauth2.get(constants.userRoute, accessToken, function (err, body/* , res */) {
|
||||||
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var json = JSON.parse(body);
|
var json = JSON.parse(body);
|
||||||
@ -136,7 +144,7 @@
|
|||||||
oAuthid: profile.id,
|
oAuthid: profile.id,
|
||||||
handle: profile.displayName,
|
handle: profile.displayName,
|
||||||
email: profile.emails[0].value,
|
email: profile.emails[0].value,
|
||||||
isAdmin: profile.isAdmin
|
isAdmin: profile.isAdmin,
|
||||||
}, function (err, user) {
|
}, function (err, user) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return done(err);
|
return done(err);
|
||||||
@ -152,7 +160,7 @@
|
|||||||
url: '/auth/' + constants.name,
|
url: '/auth/' + constants.name,
|
||||||
callbackURL: '/auth/' + constants.name + '/callback',
|
callbackURL: '/auth/' + constants.name + '/callback',
|
||||||
icon: 'fa-check-square',
|
icon: 'fa-check-square',
|
||||||
scope: (constants.scope || '').split(',')
|
scope: (constants.scope || '').split(','),
|
||||||
});
|
});
|
||||||
|
|
||||||
callback(null, strategies);
|
callback(null, strategies);
|
||||||
@ -181,8 +189,9 @@
|
|||||||
process.stdout.write('===\nAt this point, you\'ll need to customise the above section to id, displayName, and emails into the "profile" object.\n===');
|
process.stdout.write('===\nAt this point, you\'ll need to customise the above section to id, displayName, and emails into the "profile" object.\n===');
|
||||||
return callback(new Error('Congrats! So far so good -- please see server log for details'));
|
return callback(new Error('Congrats! So far so good -- please see server log for details'));
|
||||||
|
|
||||||
|
// eslint-disable-next-line
|
||||||
callback(null, profile);
|
callback(null, profile);
|
||||||
}
|
};
|
||||||
|
|
||||||
OAuth.login = function (payload, callback) {
|
OAuth.login = function (payload, callback) {
|
||||||
OAuth.getUidByOAuthid(payload.oAuthid, function (err, uid) {
|
OAuth.getUidByOAuthid(payload.oAuthid, function (err, uid) {
|
||||||
@ -193,7 +202,7 @@
|
|||||||
if (uid !== null) {
|
if (uid !== null) {
|
||||||
// Existing User
|
// Existing User
|
||||||
callback(null, {
|
callback(null, {
|
||||||
uid: uid
|
uid: uid,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// New User
|
// New User
|
||||||
@ -204,13 +213,13 @@
|
|||||||
|
|
||||||
if (payload.isAdmin) {
|
if (payload.isAdmin) {
|
||||||
Groups.join('administrators', uid, function (err) {
|
Groups.join('administrators', uid, function (err) {
|
||||||
callback(null, {
|
callback(err, {
|
||||||
uid: uid
|
uid: uid,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
callback(null, {
|
callback(null, {
|
||||||
uid: uid
|
uid: uid,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -223,7 +232,7 @@
|
|||||||
if (!uid) {
|
if (!uid) {
|
||||||
User.create({
|
User.create({
|
||||||
username: payload.handle,
|
username: payload.handle,
|
||||||
email: payload.email
|
email: payload.email,
|
||||||
}, function (err, uid) {
|
}, function (err, uid) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
@ -253,7 +262,7 @@
|
|||||||
async.apply(User.getUserField, data.uid, constants.name + 'Id'),
|
async.apply(User.getUserField, data.uid, constants.name + 'Id'),
|
||||||
function (oAuthIdToDelete, next) {
|
function (oAuthIdToDelete, next) {
|
||||||
db.deleteObjectField(constants.name + 'Id:uid', oAuthIdToDelete, next);
|
db.deleteObjectField(constants.name + 'Id:uid', oAuthIdToDelete, next);
|
||||||
}
|
},
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
winston.error('[sso-oauth] Could not remove OAuthId data for uid ' + data.uid + '. Error: ' + err);
|
winston.error('[sso-oauth] Could not remove OAuthId data for uid ' + data.uid + '. Error: ' + err);
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
"readme": "",
|
"readme": "",
|
||||||
"readmeFilename": "README.md",
|
"readmeFilename": "README.md",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"async": "^2.6.1",
|
||||||
"passport-oauth": "~1.0.0"
|
"passport-oauth": "~1.0.0"
|
||||||
},
|
},
|
||||||
"nbbpm": {
|
"nbbpm": {
|
||||||
|
@ -315,6 +315,13 @@ astral-regex@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
|
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
|
||||||
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==
|
integrity sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==
|
||||||
|
|
||||||
|
async@^2.6.1:
|
||||||
|
version "2.6.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/async/-/async-2.6.1.tgz#b245a23ca71930044ec53fa46aa00a3e87c6a610"
|
||||||
|
integrity sha512-fNEiL2+AZt6AlAw/29Cr0UDe4sRAHCpEHh54WMz+Bb7QfNcFw4h3loofyJpLeQs4Yx7yuqu/2dLgM5hKOs6HlQ==
|
||||||
|
dependencies:
|
||||||
|
lodash "^4.17.10"
|
||||||
|
|
||||||
atob@^2.1.1:
|
atob@^2.1.1:
|
||||||
version "2.1.2"
|
version "2.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
|
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
|
||||||
|
Loading…
Reference in New Issue
Block a user