Skip to content

Commit 8e7c76b

Browse files
committed
feat: oauth2 provider
1 parent 62baf5f commit 8e7c76b

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

config.sample.yml

+6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ auth:
9797
clientSecret: APP_SECRET_KEY
9898
resource: '00000002-0000-0000-c000-000000000000'
9999
tenant: 'YOUR_TENANT.onmicrosoft.com'
100+
oauth2:
101+
enabled: false
102+
clientId: OAUTH2_CLIENT_ID
103+
clientSecret: OAUTH2_CLIENT_SECRET
104+
authorizationURL: OAUTH2_AUTH_URL
105+
tokenURL: OAUTH2_TOKEN_URL
100106

101107
# ---------------------------------------------------------------------
102108
# Secret key to use when encrypting sessions

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wiki",
3-
"version": "1.0.12",
3+
"version": "1.0.0",
44
"description": "A modern, lightweight and powerful wiki app built on NodeJS, Git and Markdown",
55
"main": "wiki.js",
66
"scripts": {

server/controllers/auth.js

+2
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ router.get('/login/facebook', passport.authenticate('facebook', { scope: ['publi
9797
router.get('/login/github', passport.authenticate('github', { scope: ['user:email'] }))
9898
router.get('/login/slack', passport.authenticate('slack', { scope: ['identity.basic', 'identity.email'] }))
9999
router.get('/login/azure', passport.authenticate('azure_ad_oauth2'))
100+
router.get('/login/oauth2', passport.authenticate('oauth2'))
100101

101102
router.get('/login/ms/callback', passport.authenticate('windowslive', { failureRedirect: '/login', successRedirect: '/' }))
102103
router.get('/login/google/callback', passport.authenticate('google', { failureRedirect: '/login', successRedirect: '/' }))
103104
router.get('/login/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login', successRedirect: '/' }))
104105
router.get('/login/github/callback', passport.authenticate('github', { failureRedirect: '/login', successRedirect: '/' }))
105106
router.get('/login/slack/callback', passport.authenticate('slack', { failureRedirect: '/login', successRedirect: '/' }))
106107
router.get('/login/azure/callback', passport.authenticate('azure_ad_oauth2', { failureRedirect: '/login', successRedirect: '/' }))
108+
router.get('/login/oauth2/callback', passport.authenticate('oauth2', { failureRedirect: '/login', successRedirect: '/' }))
107109

108110
/**
109111
* Logout

server/libs/auth.js

+21
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,27 @@ module.exports = function (passport) {
205205
))
206206
}
207207

208+
// OAuth 2
209+
210+
if (appconfig.auth.oauth2 && appconfig.auth.oauth2.enabled) {
211+
const OAuth2Strategy = require('passport-oauth2').Strategy
212+
passport.use('oauth2',
213+
new OAuth2Strategy({
214+
authorizationURL: appconfig.auth.oauth2.authorizationURL,
215+
tokenURL: appconfig.auth.oauth2.tokenURL,
216+
clientID: appconfig.auth.oauth2.clientId,
217+
clientSecret: appconfig.auth.oauth2.clientSecret,
218+
callbackURL: appconfig.host + '/login/oauth2/callback'
219+
}, (accessToken, refreshToken, profile, cb) => {
220+
db.User.processProfile(profile).then((user) => {
221+
return cb(null, user) || true
222+
}).catch((err) => {
223+
return cb(err, null) || true
224+
})
225+
}
226+
))
227+
}
228+
208229
// Create users for first-time
209230

210231
db.onReady.then(() => {

0 commit comments

Comments
 (0)