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
|
2020-01-04 22:30:23 +00:00
|
|
|
const config = require('../../config')
|
2019-12-28 13:20:18 +00:00
|
|
|
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
|
|
|
})
|
|
|
|
)
|