How to use the passport-oauth2.Strategy function in passport-oauth2

To help you get started, we’ve selected a few passport-oauth2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geneontology / noctua / login.js View on Github external
// https://gist.github.com/JanKoppe/1491e37d1022c77a286087e6c81d6092#file-example-js-L5
	    
	    // TODO.
	    // Pick-up secrets file and check structure.
	    var orcid_secrets = yaml.load(provider_path);
	    console.log('secrets for ' + provider, orcid_secrets);
	    if( orcid_secrets['clientID'] &&
		orcid_secrets['clientSecret'] &&
		orcid_secrets['callbackURL'] ){
		    // Pass.
		}else{
		    throw new Error(provider + ' not structured correctly!');
		}
	    
	    var ORCIDStrategy = require('passport-oauth2').Strategy;
	    passport.use(new ORCIDStrategy({
	      passReqToCallback: true,
	      session: false,
	      authorizationURL: 'https://orcid.org/oauth/authorize',
	      tokenURL: 'https://pub.orcid.org/oauth/token',
              scope: '/authenticate',
	      clientID: orcid_secrets['clientID'],
	      clientSecret: orcid_secrets['clientSecret'],
	      callbackURL: orcid_secrets['callbackURL']
	    }, function(req, accessToken, refreshToken, params, profile, done){

		console.log("Start auth...");
		//console.log(provider + ' callback profile: ', profile);
		//console.log(provider + ' callback params: ', params);

		// Try and extract from sessioner using orcid id.
		if( ! params || ! us.isString(params['orcid']) ){
github coralproject / talk / src / core / server / app / middleware / passport / strategies / oidc / index.ts View on Github external
private createStrategy(
    req: Request,
    integration: Required
  ): OAuth2Strategy {
    const { clientID, clientSecret, authorizationURL, tokenURL } = integration;

    // Construct the callbackURL from the request.
    const callbackURL = reconstructURL(req, `/api/auth/oidc/callback`);

    // Create a new OAuth2Strategy, where we pass the verify callback bound to
    // this OIDCStrategy instance.
    return new OAuth2Strategy(
      {
        passReqToCallback: true,
        clientID,
        clientSecret,
        authorizationURL,
        tokenURL,
        callbackURL,
      },
      this.userAuthenticatedCallback
    );
  }
github rapid7 / guardian / lib / control / strategy / slack.js View on Github external
exports.initialize = function(app) {
  var users = exports.users = {};
  var params = Config.get('strategy:params');

  params.state = true;
  params.authorizationURL = 'https://slack.com/oauth/authorize';
  params.tokenURL = 'https://slack.com/api/oauth.access';
  params.callbackURL = URL.format(Util._extend(Config.get('frontend'), {
    pathname: exports.callback
  }));

  var handler = new OAuth2(params, function(token, _, profile, done) {
    profile.id = Crypto.randomBytes(36).toString('base64');
    profile.token = token;

    users[profile.id] = profile;
    done(null, profile);
  });

  // Load profile from Slack API
  handler.userProfile = function(token, done) {
    this._oauth2._request('GET', URL.format({
      protocol: 'https',
      hostname: 'slack.com',
      pathname: '/api/auth.test',
      query: {
        token: token
      }
github DefinitelyTyped / DefinitelyTyped / types / passport-oauth2 / passport-oauth2-tests.ts View on Github external
function verifyFunction4(_req: Request, _accessToken: string, _refreshToken: string, _results: any, _profile: any, verifyCallback: VerifyCallback) {
    verifyCallback(undefined, {userid: '1'});
}

const strategyOptions2: StrategyOptionsWithRequest = {
    authorizationURL: 'http://www.example.com/auth',
    callbackURL: 'http://www.example.com/callback',
    clientID: 'dummy',
    clientSecret: 'secret',
    tokenURL: 'http://www.example.com/token',
    passReqToCallback: true
};

const strategy3: PassportStrategy = new OAuth2Strategy(strategyOptions2, verifyFunction3);

const strategy4: Strategy = new Strategy(strategyOptions2, verifyFunction4);

const err1 = new AuthorizationError('Description', 'invalid_request', undefined);

const err2 = new TokenError(undefined, 'invalid_request', undefined);

const err3 = new InternalOAuthError('Hello', {});
github avoidwork / tenso / src / utility.js View on Github external
} else {
						res.redirect(config.auth.redirect);
					}
				});
			}

			function mid () {
				passportSession(req, res, final);
			}

			passportInit(req, res, mid);
		};
	}

	if (config.auth.oauth2.enabled) {
		passport.use(new OAuth2Strategy({
			authorizationURL: config.auth.oauth2.auth_url,
			tokenURL: config.auth.oauth2.token_url,
			clientID: config.auth.oauth2.client_id,
			clientSecret: config.auth.oauth2.client_secret,
			callbackURL: realm + "/auth/oauth2/callback"
		}, function (accessToken, refreshToken, profile, done) {
			config.auth.oauth2.auth(accessToken, refreshToken, profile, function (err, user) {
				if (err) {
					delete err.stack;
					return done(err);
				}

				done(null, user);
			});
		}));
github avoidwork / tenso / lib / utility.js View on Github external
} else if (req.cors && req.headers["x-requested-with"] === "XMLHttpRequest") {
						res.send("Success");
					} else {
						redirect(req, res);
					}
				});
			}

			function mid () {
				passportSession(req, res, final);
			}

			passportInit(req, res, mid);
		};
	} else if (config.auth.oauth2.enabled) {
		passport.use(new OAuth2Strategy({
			authorizationURL: config.auth.oauth2.auth_url,
			tokenURL: config.auth.oauth2.token_url,
			clientID: config.auth.oauth2.client_id,
			clientSecret: config.auth.oauth2.client_secret,
			callbackURL: realm + "/auth/oauth2/callback"
		}, (accessToken, refreshToken, profile, done) => {
			delay(() => {
				config.auth.oauth2.auth(accessToken, refreshToken, profile, (err, user) => {
					if (err !== null) {
						done(err);
					} else {
						done(null, user);
					}
				});
			}, authDelay);
		}));
github avoidwork / tenso / lib / tenso.es6.js View on Github external
} else {
						res.redirect(config.auth.redirect);
					}
				});
			}

			function mid () {
				passportSession(req, res, final);
			}

			passportInit(req, res, mid);
		};
	}

	if (config.auth.oauth2.enabled) {
		passport.use(new OAuth2Strategy({
			authorizationURL: config.auth.oauth2.auth_url,
			tokenURL: config.auth.oauth2.token_url,
			clientID: config.auth.oauth2.client_id,
			clientSecret: config.auth.oauth2.client_secret,
			callbackURL: realm + "/auth/oauth2/callback"
		}, function (accessToken, refreshToken, profile, done) {
			config.auth.oauth2.auth(accessToken, refreshToken, profile, function (err, user) {
				if (err) {
					delete err.stack;
					return done(err);
				}

				done(null, user);
			});
		}));

passport-oauth2

OAuth 2.0 authentication strategy for Passport.

MIT
Latest version published 11 months ago

Package Health Score

70 / 100
Full package analysis