'use strict'

const Router = require('express').Router
const passport = require('passport')
const BitbucketStrategy = require('passport-bitbucket-oauth2').Strategy
const config = require('../../../config')
const response = require('../../../response')
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
const { URL } = require('url')

const bitbucketAuth = module.exports = Router()

passport.use(new BitbucketStrategy({
  clientID: config.bitbucket.clientID,
  clientSecret: config.bitbucket.clientSecret,
  callbackURL: config.serverURL + '/auth/bitbucket/callback',
}, 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 + '/',
    failureRedirect: config.serverURL + '/' 
  })
)

'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,
  callbackURL: config.serverURL + '/auth/bitbucket/callback'
}, 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 + '/',
    failureRedirect: config.serverURL + '/'
  })
)

Remove unused imports, fixing coding style issues.
Remove unused imports, fixing coding style issues.

Signed-off-by: YusukeIwaki <488a597b88cf2030e9a0979097e61c65753a1a57@i3-systems.com>
