feat: support customize scope in OAuth2 provider

Signed-off-by: BoHong Li <raccoon@hackmd.io>
This commit is contained in:
BoHong Li 2020-02-28 02:13:58 +08:00
parent d5d0f3d820
commit 72c5b0d14e
No known key found for this signature in database
GPG Key ID: 06770355DC9ECD38
3 changed files with 10 additions and 7 deletions

View File

@ -15,7 +15,8 @@ passport.use(new OAuth2CustomStrategy({
clientID: config.oauth2.clientID, clientID: config.oauth2.clientID,
clientSecret: config.oauth2.clientSecret, clientSecret: config.oauth2.clientSecret,
callbackURL: config.serverURL + '/auth/oauth2/callback', callbackURL: config.serverURL + '/auth/oauth2/callback',
userProfileURL: config.oauth2.userProfileURL userProfileURL: config.oauth2.userProfileURL,
scope: config.oauth2.scope
}, passportGeneralCallback)) }, passportGeneralCallback))
oauth2Auth.get('/auth/oauth2', function (req, res, next) { oauth2Auth.get('/auth/oauth2', function (req, res, next) {

View File

@ -98,7 +98,8 @@ module.exports = {
userProfileURL: undefined, userProfileURL: undefined,
userProfileUsernameAttr: 'username', userProfileUsernameAttr: 'username',
userProfileDisplayNameAttr: 'displayName', userProfileDisplayNameAttr: 'displayName',
userProfileEmailAttr: 'email' userProfileEmailAttr: 'email',
scope: 'email'
}, },
facebook: { facebook: {
clientID: undefined, clientID: undefined,

View File

@ -88,14 +88,15 @@ module.exports = {
oauth2: { oauth2: {
providerName: process.env.CMD_OAUTH2_PROVIDERNAME, providerName: process.env.CMD_OAUTH2_PROVIDERNAME,
baseURL: process.env.CMD_OAUTH2_BASEURL, baseURL: process.env.CMD_OAUTH2_BASEURL,
clientID: process.env.CMD_OAUTH2_CLIENT_ID,
clientSecret: process.env.CMD_OAUTH2_CLIENT_SECRET,
authorizationURL: process.env.CMD_OAUTH2_AUTHORIZATION_URL,
tokenURL: process.env.CMD_OAUTH2_TOKEN_URL,
userProfileURL: process.env.CMD_OAUTH2_USER_PROFILE_URL, userProfileURL: process.env.CMD_OAUTH2_USER_PROFILE_URL,
scope: process.env.CMD_OAUTH2_SCOPE,
userProfileUsernameAttr: process.env.CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR, userProfileUsernameAttr: process.env.CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR,
userProfileDisplayNameAttr: process.env.CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR, userProfileDisplayNameAttr: process.env.CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR,
userProfileEmailAttr: process.env.CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR, userProfileEmailAttr: process.env.CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR
tokenURL: process.env.CMD_OAUTH2_TOKEN_URL,
authorizationURL: process.env.CMD_OAUTH2_AUTHORIZATION_URL,
clientID: process.env.CMD_OAUTH2_CLIENT_ID,
clientSecret: process.env.CMD_OAUTH2_CLIENT_SECRET
}, },
dropbox: { dropbox: {
clientID: process.env.CMD_DROPBOX_CLIENTID, clientID: process.env.CMD_DROPBOX_CLIENTID,