From 23aaf61b70d4975ea5cb38dcf3417f009e547bbb Mon Sep 17 00:00:00 2001 From: Evert Prants Date: Sat, 17 Sep 2022 08:10:03 +0000 Subject: [PATCH] new oauth2 server --- library.js | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/library.js b/library.js index b814dc9..971c2aa 100644 --- a/library.js +++ b/library.js @@ -49,7 +49,7 @@ const constants = Object.freeze({ type: 'oauth2', // Either 'oauth' or 'oauth2' name: 'icynet', // Something unique to your OAuth provider in lowercase, like "github", or "nodebb" - scope: 'email privilege', + scope: 'email image privileges', oauth: { requestTokenURL: '', accessTokenURL: '', @@ -58,12 +58,12 @@ consumerSecret: nconf.get('oauth:secret'), // don't change this line }, oauth2: { - authorizationURL: nconf.get('oauth:provider') + '/oauth2/authorize', - tokenURL: nconf.get('oauth:provider') + '/oauth2/token', + authorizationURL: 'https://secure.icynet.eu/oauth2/authorize', + tokenURL: 'https://secure.icynet.eu/oauth2/token', clientID: nconf.get('oauth:id'), clientSecret: nconf.get('oauth:secret'), }, - userRoute: nconf.get('oauth:provider') + '/oauth2/user' + userRoute: 'https://api.icynet.eu/api/user' }) const OAuth = {}; @@ -169,26 +169,12 @@ }; 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 = {}; - profile.id = data.id; + profile.id = data.uuid; profile.displayName = data.display_name; profile.emails = [{ value: data.email }]; - profile.isAdmin = data.privilege === 5; - profile.picture = 'https://icynet.eu/api/avatar/' + data.id - - // 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')); + profile.isAdmin = (data.privileges || []).includes('admin'); + profile.picture = data.picture; // eslint-disable-next-line callback(null, profile);