node_modules ignore

This commit is contained in:
2025-05-08 23:43:47 +02:00
parent e19d52f172
commit 4574544c9f
65041 changed files with 10593536 additions and 0 deletions

210
server/node_modules/koa-passport/lib/framework/koa.js generated vendored Normal file
View File

@@ -0,0 +1,210 @@
'use strict'
/**
* Module dependencies.
*/
const passport = require('passport')
/**
* Passport's default/connect middleware.
*/
const _initialize = require('passport/lib/middleware/initialize')
const _authenticate = require('passport/lib/middleware/authenticate')
const createReqMock = require('./request').create
/**
* Passport's initialization middleware for Koa.
*
* @return {GeneratorFunction}
* @api private
*/
function initialize(passport) {
const middleware = promisify(_initialize(passport))
return function passportInitialize(ctx, next) {
// koa <-> connect compatibility:
const userProperty = passport._userProperty || 'user'
// check ctx.req has the userProperty
if (!ctx.req.hasOwnProperty(userProperty)) {
Object.defineProperty(ctx.req, userProperty, {
enumerable: true,
get: function() {
return ctx.state[userProperty]
},
set: function(val) {
ctx.state[userProperty] = val
}
})
}
// create mock object for express' req object
const req = createReqMock(ctx, userProperty)
// add Promise-based login method
const login = req.login
ctx.login = ctx.logIn = function(user, options) {
return new Promise((resolve, reject) => {
login.call(req, user, options, err => {
if (err) reject(err)
else resolve()
})
})
}
// add Promise-based logout method
const logout = req.logout
ctx.logout = ctx.logOut = function(options) {
return new Promise((resolve, reject) => {
logout.call(req, options, err => {
if (err) reject(err)
else resolve()
})
})
}
// add aliases for passport's request extensions to Koa's context
ctx.isAuthenticated = req.isAuthenticated.bind(req)
ctx.isUnauthenticated = req.isUnauthenticated.bind(req)
return middleware(req, ctx).then(function() {
return next()
})
}
}
/**
* Passport's authenticate middleware for Koa.
*
* @param {String|Array} name
* @param {Object} options
* @param {GeneratorFunction} callback
* @return {GeneratorFunction}
* @api private
*/
function authenticate(passport, name, options, callback) {
// normalize arguments
if (typeof options === 'function') {
callback = options
options = {}
}
options = options || {}
if (callback) {
// When the callback is set, neither `next`, `res.redirect` or `res.end`
// are called. That is, a workaround to catch the `callback` is required.
// The `passportAuthenticate()` method below will therefore set
// `callback.resolve` and `callback.reject`. Then, once the authentication
// finishes, the modified callback calls the original one and afterwards
// triggers either `callback.resolve` or `callback.reject` to inform
// `passportAuthenticate()` that we are ready.
const _callback = callback
callback = function(err, user, info, status) {
try {
Promise.resolve(_callback(err, user, info, status))
.then(() => callback.resolve(false))
.catch(err => callback.reject(err))
} catch (err) {
callback.reject(err)
}
}
}
const middleware = promisify(_authenticate(passport, name, options, callback))
return function passportAuthenticate(ctx, next) {
// this functions wraps the connect middleware
// to catch `next`, `res.redirect` and `res.end` calls
const p = new Promise((resolve, reject) => {
// mock the `req` object
const req = createReqMock(ctx, options.assignProperty || passport._userProperty || 'user')
function setBodyAndResolve(content) {
if (content) ctx.body = content
resolve(false)
}
// mock the `res` object
const res = {
redirect: function(url) {
ctx.redirect(url)
resolve(false)
},
set: ctx.set.bind(ctx),
setHeader: ctx.set.bind(ctx),
end: setBodyAndResolve,
send: setBodyAndResolve,
set statusCode(status) {
ctx.status = status
},
get statusCode() {
return ctx.status
}
}
req.res = res
// update the custom callback above
if (callback) {
callback.resolve = resolve
callback.reject = reject
}
// call the connect middleware
middleware(req, res).then(resolve, reject)
})
return p.then(cont => {
// cont equals `false` when `res.redirect` or `res.end` got called
// in this case, call next to continue through Koa's middleware stack
if (cont !== false) {
return next()
}
})
}
}
/**
* Passport's authorize middleware for Koa.
*
* @param {String|Array} name
* @param {Object} options
* @param {GeneratorFunction} callback
* @return {GeneratorFunction}
* @api private
*/
function authorize(passport, name, options, callback) {
options = options || {}
options.assignProperty = 'account'
return authenticate(passport, name, options, callback)
}
/**
* Framework support for Koa.
*
* This module provides support for using Passport with Koa. It exposes
* middleware that conform to the `fn*(next)` signature and extends
* Node's built-in HTTP request object with useful authentication-related
* functions.
*
* @return {Object}
* @api protected
*/
module.exports = function() {
return {
initialize: initialize,
authenticate: authenticate,
authorize: authorize
}
}
function promisify(expressMiddleware) {
return function(req, res) {
return new Promise(function(resolve, reject) {
expressMiddleware(req, res, function(err, result) {
if (err) reject(err)
else resolve(result)
})
})
}
}

View File

@@ -0,0 +1,166 @@
// Koa and Express are fundamental different in how they deal with extensions
// to the incoming request.
// Express pollutes Node's IncomingRequest directly, while Koa keeps Node's
// IncomingRequest untouched and adds is own high-level request object.
// These both approaches are not directly compatible with each other, since
// properties/methods found in Express' `req` object are now spread between
// Koa's context, Koa's request object and the original incoming request.
// This makes moking the Express `req` object an ugly task. With ES6 we could
// simply use a Proxy, e.g.:
//
// function createReqMock(ctx) {
// // Use a proxy that forwards `req` reads to either `ctx.passport`,
// // Node's request, Koa's request or Koa's context. Writes are persistet
// // into `ctx.passport`.
// return Proxy.create(handler(ctx.passport, {
// get: function(receiver, key) {
// return ctx.passport[key] || ctx.req[key] || ctx.request[key] || ctx[key]
// }
// }))
// }
//
// However, the current Proxy implementation does not allow debugging.
// See: https://github.com/rkusa/koa-passport/issues/17
//
// Until this is fixed, koa-passport tries to properly delegate every possible
// used property/method.
'use strict'
// Property/Method names to be delegated
let keys = [
// passport
'_passport',
'authInfo',
// http.IncomingMessage
'httpVersion',
'headers',
'trailers',
'setTimeout',
'method',
'url',
'statusCode',
'socket',
'connection',
'protocol',
// Koa's context
'cookies',
'throw',
'ip',
// Others. Are not supported directly - require proper plugins/middlewares.
'param',
'params',
'route',
'xhr',
'baseUrl',
'session',
'body',
'flash'
]
// remove duplicates
keys = keys.filter(function(key, i, self) {
return self.indexOf(key) === i
})
// create a delegate for each key
const properties = {
// mock express' .get('trust proxy')
app: {
// getter returning a mock for `req.app` containing
// the `.get()` method
get: function() {
const ctx = this.ctx
return {
get: function(key) {
if (key === 'trust proxy') {
return ctx.app.proxy
}
return undefined
}
}
}
}
}
keys.forEach(function(key) {
properties[key] = {
get: function() {
const obj = getObject(this.ctx, key)
if (!obj) return undefined
// if its a function, call with the proper context
if (typeof obj[key] === 'function') {
return function() {
return obj[key].apply(obj, arguments)
}
}
// otherwise, simply return it
return obj[key]
},
set: function(value) {
const obj = getObject(this.ctx, key) || this.ctx.state
obj[key] = value
}
}
})
// test where the key is available, either in `ctx.state`, Node's request,
// Koa's request or Koa's context
function getObject(ctx, key) {
if (ctx.state && (key in ctx.state)) {
return ctx.state
}
if (key in ctx.request) {
return ctx.request
}
if (key in ctx.req) {
return ctx.req
}
if (key in ctx) {
return ctx
}
return undefined
}
const IncomingMessageExt = require('passport/lib/http/request')
exports.create = function(ctx, userProperty) {
const req = Object.create(ctx.request, properties)
Object.defineProperty(req, userProperty, {
enumerable: true,
get: function() {
return ctx.state[userProperty]
},
set: function(val) {
ctx.state[userProperty] = val
}
})
Object.defineProperty(req, 'ctx', {
enumerable: true,
get: function() {
return ctx
}
})
// add passport http.IncomingMessage extensions
req.login = IncomingMessageExt.logIn
req.logIn = IncomingMessageExt.logIn
req.logout = IncomingMessageExt.logOut
req.logOut = IncomingMessageExt.logOut
req.isAuthenticated = IncomingMessageExt.isAuthenticated
req.isUnauthenticated = IncomingMessageExt.isUnauthenticated
return req
}

25
server/node_modules/koa-passport/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
'use strict'
// prevent passport from monkey patching
const connect = require('passport/lib/framework/connect')
connect.__monkeypatchNode = function() {}
// load passport and add the koa framework
const passport = require('passport')
const Passport = require('passport').Passport
const framework = require('./framework/koa')()
passport.framework(framework)
class KoaPassport extends Passport {
constructor() {
super()
this.framework(framework)
}
}
// Export default singleton.
module.exports = passport
// Expose constructor
module.exports.KoaPassport = KoaPassport