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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-security-passportjs",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Security plugin for Federated Wiki, using passport.js",
5
5
  "author": "Paul Rodwell <paul.rodwell@btinternet.com> (http://rodwell.me)",
6
6
  "license": "MIT",
@@ -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" then schemeButtons.push({button: "<a href='/auth/oauth2' class='scheme-button oauth2-button'><span>OAuth2</span></a>"})
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
- if Array.isArray(argv.allowed_domains)
393
- allowed = argv.allowed_domains
394
- else
395
- # accommodate copy bug to be fixed soon
396
- # https://github.com/fedwiki/wiki/blob/4c6eee69e78c1ba3f3fc8d61f4450f70afb78f10/farm.coffee#L98-L103
397
- for k, v of argv.allowed_domains
398
- allowed.push v
399
- # emails = [ { value: 'ward.cunningham@gmail.com', type: 'account' } ]
400
- emails = req.session?.passport?.user?.google?.emails
401
- return false unless emails
402
- for entry in emails
403
- have = entry.value.split('@')[1]
404
- for want in allowed
405
- return true if want == have
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) ->