Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'passport-strategy' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
if (!options) throw new Error('Cognito strategy requires options');
if (!verify) throw new Error('Cognito strategy requires a verify callback');
AWS.config.region = options.region;
passport.Strategy.call(this);
this.name = 'cognito';
this._userPoolId = options.userPoolId;
this._clientId = options.clientId;
this._verify = verify;
}
// Inherit from `passport-strategy`.
util.inherits(CognitoStrategy, passport.Strategy);
/**
* Authenticate request
*
* @param {http.IncomingMessage} req
* @param {object} options
* @access protected
*/
CognitoStrategy.prototype.authenticate = function(req, options) {
var user = {};
var username = req.body.username;
var password = req.body.password;
if (!username || !password) {
const Strategy = function (options, verify) {
passport.Strategy.call(this);
this.name = 'mock';
this._options = options;
this._verify = verify;
};
this._usernameField = options.usernameField || 'username';
this._passwordField = options.passwordField || 'password';
this._region = options.region || '';
this._authUrl = options.authUrl || '';
this._tenantId = options.tenantId || '';
passport.Strategy.call(this);
this.name = 'keystone';
this._verify = verify;
this._passReqToCallback = options.passReqToCallback;
}
/**
* Inherit from `passport.Strategy`.
*/
util.inherits(Strategy, passport.Strategy);
/**
* Get value for given field from given object. Taken from passport-local,
* copyright 2011-2013 Jared Hanson
*/
var lookup = function (obj, field) {
var i, len, chain, prop;
if (!obj) { return null; }
chain = field.split(']').join('').split('[');
for (i = 0, len = chain.length; i < len; i++) {
prop = obj[chain[i]];
if (typeof(prop) === 'undefined') { return null; }
if (typeof(prop) !== 'object') { return prop; }
obj = prop;
}
return null;
if (!verify) { throw new TypeError('HTTPBearerStrategy requires a verify callback'); }
passport.Strategy.call(this);
this.name = 'bearer';
this._verify = verify;
this._realm = options.realm || 'Users';
if (options.scope) {
this._scope = (Array.isArray(options.scope)) ? options.scope : [ options.scope ];
}
this._passReqToCallback = options.passReqToCallback;
}
/**
* Inherit from `passport.Strategy`.
*/
util.inherits(Strategy, passport.Strategy);
/**
* Authenticate request based on the contents of a HTTP Bearer authorization
* header, body parameter, or query parameter.
*
* @param {Object} req
* @api protected
*/
Strategy.prototype.authenticate = function(req) {
var token;
if (req.headers && req.headers.authorization) {
var parts = req.headers.authorization.split(' ');
if (parts.length == 2) {
var scheme = parts[0]
, credentials = parts[1];
function Strategy(options, verify) {
if (typeof options == 'function') {
verify = options;
options = {};
}
if (!verify) { throw new TypeError('HTTPBearerStrategy requires a verify callback'); }
passport.Strategy.call(this);
this.name = 'bearer';
this._verify = verify;
this._realm = options.realm || 'Users';
if (options.scope) {
this._scope = (Array.isArray(options.scope)) ? options.scope : [ options.scope ];
}
this._passReqToCallback = options.passReqToCallback;
}
}
if (!verifyUsernameAndPassword) {
throw new TypeError('2FA TOTP Strategy required username and password verification callback');
}
if (!this._skipTotpVerification && !verifyTotpCode) {
throw new TypeError('2FA TOTP Strategy required TOTP code verification callback');
}
this._usernameField = options.usernameField || 'username';
this._passwordField = options.passwordField || 'password';
this._codeField = options.codeField || 'code';
this._window = options.window || 6;
passport.Strategy.call(this);
this.name = '2fa-totp';
this._verifyUsernameAndPassword = verifyUsernameAndPassword;
this._verifyTotpCode = verifyTotpCode;
this._passReqToCallback = options.passReqToCallback || false;
}
}
this._passReqToCallback = options.passReqToCallback;
var jsonWebTokenOptions = options.jsonWebTokenOptions || {};
//for backwards compatibility, still allowing you to pass
//audience / issuer / algorithms / ignoreExpiration
//on the options.
this._verifOpts = assign({}, jsonWebTokenOptions, {
audience: options.audience,
issuer: options.issuer,
algorithms: options.algorithms,
ignoreExpiration: !!options.ignoreExpiration
});
}
util.inherits(JwtStrategy, passport.Strategy);
/**
* Allow for injection of JWT Verifier.
*
* This improves testability by allowing tests to cleanly isolate failures in the JWT Verification
* process from failures in the passport related mechanics of authentication.
*
* Note that this should only be replaced in tests.
*/
JwtStrategy.JwtVerifier = require('./verify_jwt');
/**
import * as passportStrategy from 'passport-strategy';
export class BearerStrategy extends passportStrategy.Strategy {
name: string;
private _verify: Function;
constructor(verify: Function)
{
if (!verify) {
throw new TypeError('BearerStrategy requires a verify callback');
}
super();
this.name = 'bearer';
this._verify = verify;
}
function ClientStrategy (options, verify) {
if (typeof options == 'function') {
verify = options;
options = {};
}
if (!verify)
throw new Error('OAuth 2.0 client strategy requires a verify function');
passport.Strategy.call (this);
this.name = 'oauth2-client';
this._verify = verify;
this._passReqToCallback = options.passReqToCallback;
}
passport.Strategy.call(this)
this.name = 'wechat-enterprise'
this._verify = verify
this._oauth = new OAuth2(options.corpId, options.corpSecret, _getAccessToken, _saveAccessToken)
this._callbackURL = options.callbackURL
this._scope = options.scope
this._scopeSeparator = options.scopeSeparator || ' '
this._state = options.state
this._passReqToCallback = options.passReqToCallback
}
/**
* Inherit from `passport.Strategy`.
*/
util.inherits(WechatEnterpriseStrategy, passport.Strategy)
/**
* Authenticate request by delegating to a service provider using OAuth 2.0.
*
* @param {Object} req
* @api protected
*/
WechatEnterpriseStrategy.prototype.authenticate = function(req, options) {
options = options || {}
var self = this
var callbackURL = options.callbackURL || this._callbackURL
if (callbackURL) {
var parsed = url.parse(callbackURL)
if (!parsed.protocol) {