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
|
||||
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.
|
||||
*/
|
||||
|
||||
var User = module.parent.require('./user'),
|
||||
Groups = module.parent.require('./groups'),
|
||||
meta = module.parent.require('./meta'),
|
||||
db = module.parent.require('../src/database'),
|
||||
passport = module.parent.require('passport'),
|
||||
fs = module.parent.require('fs'),
|
||||
path = module.parent.require('path'),
|
||||
nconf = module.parent.require('nconf'),
|
||||
winston = module.parent.require('winston'),
|
||||
async = module.parent.require('async');
|
||||
const User = require.main.require('./src/user');
|
||||
const Groups = require.main.require('./src/groups');
|
||||
const db = require.main.require('./src/database');
|
||||
const authenticationController = require.main.require('./src/controllers/authentication');
|
||||
|
||||
const async = require('async');
|
||||
|
||||
const passport = module.parent.require('passport');
|
||||
const nconf = module.parent.require('nconf');
|
||||
const winston = module.parent.require('winston');
|
||||
|
||||
var authenticationController = module.parent.require('./controllers/authentication');
|
||||
|
||||
/**
|
||||
* REMEMBER
|
||||
@ -64,10 +63,15 @@
|
||||
clientID: nconf.get('oauth:id'), // 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)
|
||||
}),
|
||||
configOk = false,
|
||||
OAuth = {}, passportOAuth, opts;
|
||||
userRoute: '', // This is the address to your app's "user profile" API endpoint (expects JSON)
|
||||
});
|
||||
|
||||
|
||||
var configOk = false;
|
||||
|
||||
|
||||
var OAuth = {}; var passportOAuth; var
|
||||
opts;
|
||||
|
||||
if (!constants.name) {
|
||||
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';
|
||||
|
||||
passportOAuth.Strategy.prototype.userProfile = function (token, secret, params, done) {
|
||||
this._oauth.get(constants.userRoute, token, secret, function(err, body, res) {
|
||||
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
|
||||
this._oauth.get(constants.userRoute, token, secret, function (err, body/* , res */) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
try {
|
||||
var json = JSON.parse(body);
|
||||
@ -111,8 +117,10 @@
|
||||
opts.callbackURL = nconf.get('url') + '/auth/' + constants.name + '/callback';
|
||||
|
||||
passportOAuth.Strategy.prototype.userProfile = function (accessToken, done) {
|
||||
this._oauth2.get(constants.userRoute, accessToken, function(err, body, res) {
|
||||
if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }
|
||||
this._oauth2.get(constants.userRoute, accessToken, function (err, body/* , res */) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
|
||||
try {
|
||||
var json = JSON.parse(body);
|
||||
@ -136,7 +144,7 @@
|
||||
oAuthid: profile.id,
|
||||
handle: profile.displayName,
|
||||
email: profile.emails[0].value,
|
||||
isAdmin: profile.isAdmin
|
||||
isAdmin: profile.isAdmin,
|
||||
}, function (err, user) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
@ -152,7 +160,7 @@
|
||||
url: '/auth/' + constants.name,
|
||||
callbackURL: '/auth/' + constants.name + '/callback',
|
||||
icon: 'fa-check-square',
|
||||
scope: (constants.scope || '').split(',')
|
||||
scope: (constants.scope || '').split(','),
|
||||
});
|
||||
|
||||
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===');
|
||||
return callback(new Error('Congrats! So far so good -- please see server log for details'));
|
||||
|
||||
// eslint-disable-next-line
|
||||
callback(null, profile);
|
||||
}
|
||||
};
|
||||
|
||||
OAuth.login = function (payload, callback) {
|
||||
OAuth.getUidByOAuthid(payload.oAuthid, function (err, uid) {
|
||||
@ -193,7 +202,7 @@
|
||||
if (uid !== null) {
|
||||
// Existing User
|
||||
callback(null, {
|
||||
uid: uid
|
||||
uid: uid,
|
||||
});
|
||||
} else {
|
||||
// New User
|
||||
@ -204,13 +213,13 @@
|
||||
|
||||
if (payload.isAdmin) {
|
||||
Groups.join('administrators', uid, function (err) {
|
||||
callback(null, {
|
||||
uid: uid
|
||||
callback(err, {
|
||||
uid: uid,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
callback(null, {
|
||||
uid: uid
|
||||
uid: uid,
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -223,7 +232,7 @@
|
||||
if (!uid) {
|
||||
User.create({
|
||||
username: payload.handle,
|
||||
email: payload.email
|
||||
email: payload.email,
|
||||
}, function (err, uid) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
@ -253,7 +262,7 @@
|
||||
async.apply(User.getUserField, data.uid, constants.name + 'Id'),
|
||||
function (oAuthIdToDelete, next) {
|
||||
db.deleteObjectField(constants.name + 'Id:uid', oAuthIdToDelete, next);
|
||||
}
|
||||
},
|
||||
], function (err) {
|
||||
if (err) {
|
||||
winston.error('[sso-oauth] Could not remove OAuthId data for uid ' + data.uid + '. Error: ' + err);
|
||||
|
@ -28,6 +28,7 @@
|
||||
"readme": "",
|
||||
"readmeFilename": "README.md",
|
||||
"dependencies": {
|
||||
"async": "^2.6.1",
|
||||
"passport-oauth": "~1.0.0"
|
||||
},
|
||||
"nbbpm": {
|
||||
|
@ -315,6 +315,13 @@ astral-regex@^1.0.0:
|
||||
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9"
|
||||
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:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/atob/-/atob-2.1.2.tgz#6d9517eb9e030d2436666651e86bd9f6f13533c9"
|
||||
|
Loading…
Reference in New Issue
Block a user