new oauth2 server

This commit is contained in:
Evert Prants 2022-09-17 08:10:03 +00:00
parent 1b15b4f3b7
commit 23aaf61b70

View File

@ -49,7 +49,7 @@
const constants = Object.freeze({ const constants = Object.freeze({
type: 'oauth2', // Either 'oauth' or 'oauth2' type: 'oauth2', // Either 'oauth' or 'oauth2'
name: 'icynet', // Something unique to your OAuth provider in lowercase, like "github", or "nodebb" name: 'icynet', // Something unique to your OAuth provider in lowercase, like "github", or "nodebb"
scope: 'email privilege', scope: 'email image privileges',
oauth: { oauth: {
requestTokenURL: '', requestTokenURL: '',
accessTokenURL: '', accessTokenURL: '',
@ -58,12 +58,12 @@
consumerSecret: nconf.get('oauth:secret'), // don't change this line consumerSecret: nconf.get('oauth:secret'), // don't change this line
}, },
oauth2: { oauth2: {
authorizationURL: nconf.get('oauth:provider') + '/oauth2/authorize', authorizationURL: 'https://secure.icynet.eu/oauth2/authorize',
tokenURL: nconf.get('oauth:provider') + '/oauth2/token', tokenURL: 'https://secure.icynet.eu/oauth2/token',
clientID: nconf.get('oauth:id'), clientID: nconf.get('oauth:id'),
clientSecret: nconf.get('oauth:secret'), clientSecret: nconf.get('oauth:secret'),
}, },
userRoute: nconf.get('oauth:provider') + '/oauth2/user' userRoute: 'https://api.icynet.eu/api/user'
}) })
const OAuth = {}; const OAuth = {};
@ -169,26 +169,12 @@
}; };
OAuth.parseUserReturn = function (data, callback) { OAuth.parseUserReturn = function (data, callback) {
// Alter this section to include whatever data is necessary
// NodeBB *requires* the following: id, displayName, emails.
// Everything else is optional.
// Find out what is available by uncommenting this line:
// console.log(data);
var profile = {}; var profile = {};
profile.id = data.id; profile.id = data.uuid;
profile.displayName = data.display_name; profile.displayName = data.display_name;
profile.emails = [{ value: data.email }]; profile.emails = [{ value: data.email }];
profile.isAdmin = data.privilege === 5; profile.isAdmin = (data.privileges || []).includes('admin');
profile.picture = 'https://icynet.eu/api/avatar/' + data.id profile.picture = data.picture;
// Do you want to automatically make somebody an admin? This line might help you do that...
// profile.isAdmin = data.isAdmin ? true : false;
// Delete or comment out the next TWO (2) lines when you are ready to proceed
//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 // eslint-disable-next-line
callback(null, profile); callback(null, profile);