2019-12-28 13:20:18 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const Router = require('express').Router
|
|
|
|
const passport = require('passport')
|
|
|
|
const BitbucketStrategy = require('passport-bitbucket-oauth2').Strategy
|
|
|
|
const config = require('../../../config')
|
|
|
|
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
|
|
|
|
|
|
|
|
const bitbucketAuth = module.exports = Router()
|
|
|
|
|
|
|
|
passport.use(new BitbucketStrategy({
|
|
|
|
clientID: config.bitbucket.clientID,
|
|
|
|
clientSecret: config.bitbucket.clientSecret,
|
2019-12-28 14:00:58 +00:00
|
|
|
callbackURL: config.serverURL + '/auth/bitbucket/callback'
|
2019-12-28 13:20:18 +00:00
|
|
|
}, passportGeneralCallback))
|
|
|
|
|
|
|
|
bitbucketAuth.get('/auth/bitbucket', function (req, res, next) {
|
|
|
|
setReturnToFromReferer(req)
|
|
|
|
passport.authenticate('bitbucket')(req, res, next)
|
|
|
|
})
|
|
|
|
|
|
|
|
// bitbucket auth callback
|
|
|
|
bitbucketAuth.get('/auth/bitbucket/callback',
|
|
|
|
passport.authenticate('bitbucket', {
|
|
|
|
successReturnToOrRedirect: config.serverURL + '/',
|
2019-12-28 14:00:58 +00:00
|
|
|
failureRedirect: config.serverURL + '/'
|
2019-12-28 13:20:18 +00:00
|
|
|
})
|
|
|
|
)
|