How to use the passport-oauth2.prototype 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 reactioncommerce / example-storefront / src / serverAuth.js View on Github external
const OAuth2Strategy = require("passport-oauth2");
const passport = require("passport");
const config = require("./config");
const { decodeOpaqueId } = require("./lib/utils/decoding");
const logger = require("./lib/logger");

// This is needed to allow custom parameters (e.g. loginActions) to be included
// when requesting authorization. This is setup to allow only loginAction to pass through
OAuth2Strategy.prototype.authorizationParams = function (options = {}) {
  return { loginAction: options.loginAction };
};

passport.use(
  "oauth2",
  new OAuth2Strategy(
    {
      authorizationURL: config.OAUTH2_AUTH_URL,
      tokenURL: config.OAUTH2_TOKEN_URL,
      clientID: config.OAUTH2_CLIENT_ID,
      clientSecret: config.OAUTH2_CLIENT_SECRET,
      callbackURL: config.OAUTH2_REDIRECT_URL,
      state: true,
      scope: ["offline"]
    },
    (accessToken, refreshToken, profile, cb) => {
github shanhuiyang / TypeScript-MERN-Starter / server / config / oauth2orize-strategy.ts View on Github external
// All resource server who would like to authorize from the oauth2orize server
// must use this strategy instead of OAuth2Strategy
// The Spec of OAuth2 defined 4 roles, which are user, resource server, client and authorization server.
// This file is part of **authorization server**

import OAuth2Strategy from "passport-oauth2";
import AccessTokenCollection from "../models/OAuth/AccessTokenCollection";
import AccessToken from "../models/OAuth/AccessToken";
import UserCollection from "../models/User/UserCollection";
import UserDocument from "../models/User/UserDocument";
import User from "../../client/core/src/models/User";

OAuth2Strategy.prototype.userProfile = (token: string, done: (err?: Error | null, profile?: User) => void) => {
    AccessTokenCollection.findOne(
        {token: token},
        (error: Error, accessToken: AccessToken): void => {
            if (error || !accessToken) {
                done(error);
            }
            UserCollection.findById(accessToken.userId, (error: Error, user: UserDocument): void => {
                if (error || !user) {
                    done(error);
                }
                done(undefined, user);
            });
        }
    );
};
github IvanWei / passport-line-auth / lib / strategy.js View on Github external
Strategy.prototype.authenticate = function(req, options) {
  if (req.query && req.query.error_code && !req.query.error) {
    return this.error(new lineAuthorizationError(req.query.error_message, parseInt(req.query.error_code, 10)));
  }

  OAuth2Strategy.prototype.authenticate.call(this, req, options);
};

passport-oauth2

OAuth 2.0 authentication strategy for Passport.

MIT
Latest version published 3 months ago

Package Health Score

73 / 100
Full package analysis