|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const Router = require('express').Router |
| 4 | +const passport = require('passport') |
| 5 | +const BitbucketStrategy = require('passport-bitbucket-oauth2').Strategy |
| 6 | +const config = require('../../../config') |
| 7 | +const response = require('../../../response') |
| 8 | +const { setReturnToFromReferer, passportGeneralCallback } = require('../utils') |
| 9 | +const { URL } = require('url') |
| 10 | + |
| 11 | +const bitbucketAuth = module.exports = Router() |
| 12 | + |
| 13 | +passport.use(new BitbucketStrategy({ |
| 14 | + clientID: config.bitbucket.clientID, |
| 15 | + clientSecret: config.bitbucket.clientSecret, |
| 16 | + callbackURL: config.serverURL + '/auth/bitbucket/callback', |
| 17 | +}, passportGeneralCallback)) |
| 18 | + |
| 19 | +bitbucketAuth.get('/auth/bitbucket', function (req, res, next) { |
| 20 | + setReturnToFromReferer(req) |
| 21 | + passport.authenticate('bitbucket')(req, res, next) |
| 22 | +}) |
| 23 | + |
| 24 | +// bitbucket auth callback |
| 25 | +bitbucketAuth.get('/auth/bitbucket/callback', |
| 26 | + passport.authenticate('bitbucket', { |
| 27 | + successReturnToOrRedirect: config.serverURL + '/', |
| 28 | + failureRedirect: config.serverURL + '/' |
| 29 | + }) |
| 30 | +) |
0 commit comments