wiki-security-passportjs 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/social.coffee +37 -23
package/package.json
CHANGED
package/server/social.coffee
CHANGED
|
@@ -17,6 +17,8 @@ url = require 'url'
|
|
|
17
17
|
_ = require 'lodash'
|
|
18
18
|
glob = require 'glob'
|
|
19
19
|
|
|
20
|
+
{ jwtDecode } = require('jwt-decode');
|
|
21
|
+
|
|
20
22
|
passport = require('passport')
|
|
21
23
|
|
|
22
24
|
# Export a function that generates security handler
|
|
@@ -164,8 +166,6 @@ module.exports = exports = (log, loga, argv) ->
|
|
|
164
166
|
|
|
165
167
|
if argv.oauth2_UserInfoURL?
|
|
166
168
|
OAuth2Strategy::userProfile = (accesstoken, done) ->
|
|
167
|
-
console.log "hello"
|
|
168
|
-
console.log accesstoken
|
|
169
169
|
@_oauth2._request "GET", argv.oauth2_UserInfoURL, null, null, accesstoken, (err, data) ->
|
|
170
170
|
if err
|
|
171
171
|
return done err
|
|
@@ -185,6 +185,8 @@ module.exports = exports = (log, loga, argv) ->
|
|
|
185
185
|
userInfoURL: argv.oauth2_UserInfoURL
|
|
186
186
|
}, (accessToken, refreshToken, params, profile, cb) ->
|
|
187
187
|
|
|
188
|
+
token = jwtDecode(accessToken)
|
|
189
|
+
|
|
188
190
|
extractUserInfo = (uiParam, uiDef) ->
|
|
189
191
|
uiPath = ''
|
|
190
192
|
if typeof uiParam == 'undefined' then (uiPath = uiDef) else (uiPath = uiParam)
|
|
@@ -192,6 +194,8 @@ module.exports = exports = (log, loga, argv) ->
|
|
|
192
194
|
sParts = uiPath.split('.')
|
|
193
195
|
sFrom = sParts.shift()
|
|
194
196
|
switch sFrom
|
|
197
|
+
when "token"
|
|
198
|
+
obj = token
|
|
195
199
|
when "params"
|
|
196
200
|
obj = params
|
|
197
201
|
when "profile"
|
|
@@ -204,10 +208,6 @@ module.exports = exports = (log, loga, argv) ->
|
|
|
204
208
|
obj = obj[sParts.shift()]
|
|
205
209
|
return obj
|
|
206
210
|
|
|
207
|
-
console.log("accessToken", accessToken)
|
|
208
|
-
console.log("refreshToken", refreshToken)
|
|
209
|
-
console.log("params", params)
|
|
210
|
-
console.log("profile", profile)
|
|
211
211
|
if argv.oauth2_UsernameField?
|
|
212
212
|
username_query = argv.oauth2_UsernameField
|
|
213
213
|
else
|
|
@@ -336,7 +336,14 @@ module.exports = exports = (log, loga, argv) ->
|
|
|
336
336
|
schemeButtons = []
|
|
337
337
|
_(ids).forEach (scheme) ->
|
|
338
338
|
switch scheme
|
|
339
|
-
when "oauth2"
|
|
339
|
+
when "oauth2"
|
|
340
|
+
schemeButtons.push({button: "<a href='/auth/oauth2' id='oauth2' class='scheme-button oauth2-button'><span>OAuth2</span></a>
|
|
341
|
+
<script>
|
|
342
|
+
oauth2Button = document.getElementById('oauth2');
|
|
343
|
+
oauth2Button.onclick = function(event) {
|
|
344
|
+
window.resizeBy(0, +300);
|
|
345
|
+
}
|
|
346
|
+
</script>"})
|
|
340
347
|
when "twitter" then schemeButtons.push({button: "<a href='/auth/twitter' class='scheme-button twitter-button'><span>Twitter</span></a>"})
|
|
341
348
|
when "github" then schemeButtons.push({button: "<a href='/auth/github' class='scheme-button github-button'><span>Github</span></a>"})
|
|
342
349
|
when "google"
|
|
@@ -385,24 +392,31 @@ module.exports = exports = (log, loga, argv) ->
|
|
|
385
392
|
# see http://ward.asia.wiki.org/login-to-view.html
|
|
386
393
|
|
|
387
394
|
if argv.restricted?
|
|
388
|
-
|
|
389
395
|
allowedToView = (req) ->
|
|
390
|
-
allowed = []
|
|
391
396
|
if argv.allowed_domains?
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
397
|
+
try
|
|
398
|
+
allowed_domains = argv.allowed_domains
|
|
399
|
+
emails = req.session.passport.user.google.emails
|
|
400
|
+
for entry in emails
|
|
401
|
+
have = entry.value.split('@')[1]
|
|
402
|
+
for want in allowed_domains
|
|
403
|
+
return true if want == have
|
|
404
|
+
catch error
|
|
405
|
+
if emails?
|
|
406
|
+
console.log "argv.allowed_domains exists, but there was an error. Make sure it's value is an array in your config."
|
|
407
|
+
if argv.allowed_ids?
|
|
408
|
+
try
|
|
409
|
+
allowed_ids = argv.allowed_ids
|
|
410
|
+
idProvider = _.head(_.keys(req.session.passport.user))
|
|
411
|
+
switch idProvider
|
|
412
|
+
when 'github', 'twitter', 'oauth2'
|
|
413
|
+
id = req.session.passport.user[idProvider].id
|
|
414
|
+
return true if (allowed_ids.length == 1 and allowed_ids[0] == "*")
|
|
415
|
+
for want in allowed_ids
|
|
416
|
+
return true if want == id
|
|
417
|
+
catch error
|
|
418
|
+
if idProvider?
|
|
419
|
+
console.log "argv.allowed_ids exists, but there was an error. Make sure it's value is an array in your config."
|
|
406
420
|
false
|
|
407
421
|
|
|
408
422
|
app.all '*', (req, res, next) ->
|