Guest User

Untitled

a guest
Jun 13th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. passport.use(new OAuth2Strategy({
  2. authorizationURL: 'https://www.example.com/oauth2/authorize',
  3. tokenURL: 'https://www.example.com/oauth2/token',
  4. clientID: EXAMPLE_CLIENT_ID,
  5. clientSecret: EXAMPLE_CLIENT_SECRET,
  6. callbackURL: "http://localhost:3000/auth/example/callback"
  7. },
  8. function(accessToken, refreshToken, profile, cb) {
  9. // Do whatever here with the profile
  10. }
  11. ));
  12.  
  13. app.get('/auth/example/callback',
  14. passport.authenticate('oauth2', { failureRedirect: '/login' }),
  15. function(req, res) {
  16. // Successful authentication, redirect home.
  17. res.redirect('/');
  18. });
  19.  
  20. 'use strict';
  21.  
  22. var OAuth2 = require('oauth').OAuth2;
  23.  
  24. function getTokenFromCode (code, clientID, clientSecret, authorizationURL, tokenURL) {
  25. return () => {
  26. var oAuth2 = new OAuth2(clientID, config.clientSecret,
  27. '', config.authorizationURL, config.tokenURL);
  28. var _getOAuthAccessToken = oAuth2.getOAuthAccessToken;
  29. oAuth2.getOAuthAccessToken = (code, params, callback) => {
  30. if (responseType) {
  31. params.response_type = responseType;
  32. }
  33. _getOAuthAccessToken.call(oAuth2, code, params, callback);
  34. };
  35. return oAuth2;
  36. };
  37. }
Add Comment
Please, Sign In to add comment