Revert "Tidy up OAuth, allow pulling properties from decoded JWT"

This reverts commit b28d90fcc3.
This commit is contained in:
3wc
2024-10-30 22:21:20 -04:00
parent cb9e0ceed3
commit c7322416c6
3 changed files with 12 additions and 17 deletions

9
package-lock.json generated
View File

@ -11,7 +11,6 @@
"dependencies": {
"@passport-js/passport-twitter": "^1.0.8",
"coffeescript": "^2.4.1",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.19",
"passport": "^0.3.2",
"passport-github2": "^0.1.12",
@ -4330,14 +4329,6 @@
"dev": true,
"license": "ISC"
},
"node_modules/jwt-decode": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-4.0.0.tgz",
"integrity": "sha512-+KJGIyHgkGuIq3IEBNftfhW/LfWhXUIY6OmyVWjliu5KH1y0fw7VQ8YndE2O4qZdMSd9SqbnC8GOcZEy0Om7sA==",
"engines": {
"node": ">=18"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",

View File

@ -7,7 +7,6 @@
"dependencies": {
"@passport-js/passport-twitter": "^1.0.8",
"coffeescript": "^2.4.1",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.19",
"passport": "^0.3.2",
"passport-github2": "^0.1.12",

View File

@ -17,8 +17,6 @@ url = require 'url'
_ = require 'lodash'
glob = require 'glob'
{ jwtDecode } = require('jwt-decode');
passport = require('passport')
# Export a function that generates security handler
@ -52,6 +50,10 @@ module.exports = exports = (log, loga, argv) ->
callbackHost = callbackHost + ":" + url.parse(argv.url).port
else
callbackHost = url.parse(argv.url).host
if argv.oauth2_CallbackPort?
callbackHost = callbackHost + ":" + argv.oauth2_CallbackPort
console.log "callbackHost", callbackHost
ids = []
@ -133,7 +135,7 @@ module.exports = exports = (log, loga, argv) ->
return false
switch idProvider
when "github", "google", "twitter", 'oauth2'
when "github", "google", "twitter", "oauth2"
if _.isEqual(admin[idProvider], req.session.passport.user[idProvider].id)
return true
else
@ -163,10 +165,13 @@ module.exports = exports = (log, loga, argv) ->
OAuth2Strategy = require('passport-oauth2').Strategy
oauth2StrategyName = callbackHost + 'OAuth'
console.log "callbackHost", callbackHost
if argv.oauth2_UserInfoURL?
OAuth2Strategy::userProfile = (accesstoken, done) ->
@_oauth2._request "GET", argv.oauth2_UserInfoURL, null, null, accesstoken, (err, data) ->
console.log "data", data
console.log "err", err
if err
return done err
try
@ -185,8 +190,6 @@ module.exports = exports = (log, loga, argv) ->
userInfoURL: argv.oauth2_UserInfoURL
}, (accessToken, refreshToken, params, profile, cb) ->
token = jwtDecode(accessToken)
extractUserInfo = (uiParam, uiDef) ->
uiPath = ''
if typeof uiParam == 'undefined' then (uiPath = uiDef) else (uiPath = uiParam)
@ -194,8 +197,6 @@ module.exports = exports = (log, loga, argv) ->
sParts = uiPath.split('.')
sFrom = sParts.shift()
switch sFrom
when "token"
obj = token
when "params"
obj = params
when "profile"
@ -208,6 +209,10 @@ module.exports = exports = (log, loga, argv) ->
obj = obj[sParts.shift()]
return obj
console.log("accessToken", accessToken)
console.log("refreshToken", refreshToken)
console.log("params", params)
console.log("profile", profile)
if argv.oauth2_UsernameField?
username_query = argv.oauth2_UsernameField
else