Skip to content

Commit d5dd27f

Browse files
author
YusukeIwaki
committed
Implement bitbucket login.
Signed-off-by: YusukeIwaki <iwaki+git@i3-systems.com>
1 parent 3f089c7 commit d5dd27f

File tree

9 files changed

+58
-7
lines changed

9 files changed

+58
-7
lines changed

app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ app.locals.authProviders = {
186186
facebook: config.isFacebookEnable,
187187
twitter: config.isTwitterEnable,
188188
github: config.isGitHubEnable,
189+
bitbucket: config.isBitbucketEnable,
189190
gitlab: config.isGitLabEnable,
190191
mattermost: config.isMattermostEnable,
191192
dropbox: config.isDropboxEnable,

lib/config/environment.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ module.exports = {
7070
clientID: process.env.CMD_GITHUB_CLIENTID,
7171
clientSecret: process.env.CMD_GITHUB_CLIENTSECRET
7272
},
73+
bitbucket: {
74+
clientID: process.env.CMD_BITBUCKET_CLIENTID,
75+
clientSecret: process.env.CMD_BITBUCKET_CLIENTSECRET
76+
},
7377
gitlab: {
7478
baseURL: process.env.CMD_GITLAB_BASEURL,
7579
clientID: process.env.CMD_GITLAB_CLIENTID,

lib/config/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ config.isTwitterEnable = config.twitter.consumerKey && config.twitter.consumerSe
121121
config.isEmailEnable = config.email
122122
config.isOpenIDEnable = config.openID
123123
config.isGitHubEnable = config.github.clientID && config.github.clientSecret
124+
config.isBitbucketEnable = config.bitbucket.clientID && config.bitbucket.clientSecret
124125
config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret
125126
config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret
126127
config.isLDAPEnable = config.ldap.url

lib/web/auth/bitbucket/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
)

lib/web/auth/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ passport.deserializeUser(function (id, done) {
3737
if (config.isFacebookEnable) authRouter.use(require('./facebook'))
3838
if (config.isTwitterEnable) authRouter.use(require('./twitter'))
3939
if (config.isGitHubEnable) authRouter.use(require('./github'))
40+
if (config.isBitbucketEnable) authRouter.use(require('./bitbucket'))
4041
if (config.isGitLabEnable) authRouter.use(require('./gitlab'))
4142
if (config.isMattermostEnable) authRouter.use(require('./mattermost'))
4243
if (config.isDropboxEnable) authRouter.use(require('./dropbox'))

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"passport-dropbox-oauth2": "~1.1.0",
111111
"passport-facebook": "~2.1.1",
112112
"passport-github": "~1.1.0",
113+
"passport-bitbucket-oauth2": "~0.1.2",
113114
"passport-gitlab2": "~4.0.0",
114115
"passport-google-oauth20": "~1.0.0",
115116
"passport-ldapauth": "~2.1.3",

public/views/index/body.ejs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<% if (allowAnonymous) { %>
1616
<a type="button" href="<%- serverURL %>/new" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> <%= __('New guest note') %></a>
1717
<% } %>
18-
<% if (authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.saml || authProviders.oauth2 || authProviders.email) { %>
18+
<% if (authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.bitbucket || authProviders.gitlab ||authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.saml || authProviders.oauth2 || authProviders.email) { %>
1919
<button class="btn btn-sm btn-success ui-signin" data-toggle="modal" data-target=".signin-modal"><%= __('Sign In') %></button>
2020
<% } %>
2121
</div>
@@ -50,7 +50,7 @@
5050
<% if (errorMessage && errorMessage.length > 0) { %>
5151
<div class="alert alert-danger" style="max-width: 400px; margin: 0 auto;"><%= errorMessage %></div>
5252
<% } %>
53-
<% if (authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.saml || authProviders.oauth2 || authProviders.email) { %>
53+
<% if (authProviders.facebook || authProviders.twitter || authProviders.github|| authProviders.bitbucket || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.saml || authProviders.oauth2 || authProviders.email) { %>
5454
<span class="ui-signin">
5555
<br>
5656
<a type="button" class="btn btn-lg btn-success ui-signin" data-toggle="modal" data-target=".signin-modal" style="min-width: 200px;"><%= __('Sign In') %></a>

public/views/shared/signin-modal.ejs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
<i class="fa fa-github"></i> <%= __('Sign in via %s', 'GitHub') %>
2424
</a>
2525
<% } %>
26+
<% if (authProviders.bitbucket) { %>
27+
<a href="<%- serverURL %>/auth/bitbucket" class="btn btn-lg btn-block btn-social btn-bitbucket">
28+
<i class="fa fa-bitbucket"></i> <%= __('Sign in via %s', 'Bitbucket') %>
29+
</a>
30+
<% } %>
2631
<% if (authProviders.gitlab) { %>
2732
<a href="<%- serverURL %>/auth/gitlab" class="btn btn-lg btn-block btn-social btn-gitlab">
2833
<i class="fa fa-gitlab"></i> <%= __('Sign in via %s', 'GitLab') %>
@@ -53,7 +58,7 @@
5358
<i class="fa fa-mail-forward"></i> <%= __('Sign in via %s', authProviders.oauth2ProviderName || 'OAuth2') %>
5459
</a>
5560
<% } %>
56-
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.saml || authProviders.oauth2) && authProviders.ldap) { %>
61+
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.bitbucket || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.saml || authProviders.oauth2) && authProviders.ldap) { %>
5762
<hr>
5863
<% }%>
5964
<% if (authProviders.ldap) { %>
@@ -78,7 +83,7 @@
7883
</div>
7984
</form>
8085
<% } %>
81-
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.oauth2) && authProviders.openID) { %>
86+
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.bitbucket || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.oauth2) && authProviders.openID) { %>
8287
<hr>
8388
<% }%>
8489
<% if (authProviders.openID) { %>
@@ -97,7 +102,7 @@
97102
</div>
98103
</form>
99104
<% } %>
100-
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.oauth2 || authProviders.openID) && authProviders.email) { %>
105+
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github|| authProviders.bitbucket || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.oauth2 || authProviders.openID) && authProviders.email) { %>
101106
<hr>
102107
<% }%>
103108
<% if (authProviders.email) { %>

yarn.lock

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9357,6 +9357,14 @@ pascalcase@^0.1.1:
93579357
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
93589358
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=
93599359

9360+
passport-bitbucket-oauth2@~0.1.2:
9361+
version "0.1.2"
9362+
resolved "https://registry.yarnpkg.com/passport-bitbucket-oauth2/-/passport-bitbucket-oauth2-0.1.2.tgz#eb3af5cdd0d06830adc49b76acae4ad82290693b"
9363+
integrity sha1-6zr1zdDQaDCtxJt2rK5K2CKQaTs=
9364+
dependencies:
9365+
passport-oauth2 "^1.1.2"
9366+
pkginfo "0.2.x"
9367+
93609368
passport-dropbox-oauth2@~1.1.0:
93619369
version "1.1.0"
93629370
resolved "https://registry.yarnpkg.com/passport-dropbox-oauth2/-/passport-dropbox-oauth2-1.1.0.tgz#77c737636e4841944dfb82dfc42c3d8ab782c10e"
@@ -9419,7 +9427,7 @@ passport-oauth1@1.x.x:
94199427
passport-strategy "1.x.x"
94209428
utils-merge "1.x.x"
94219429

9422-
passport-oauth2@1.x.x, passport-oauth2@^1.4.0:
9430+
passport-oauth2@1.x.x, passport-oauth2@^1.1.2, passport-oauth2@^1.4.0:
94239431
version "1.5.0"
94249432
resolved "https://registry.yarnpkg.com/passport-oauth2/-/passport-oauth2-1.5.0.tgz#64babbb54ac46a4dcab35e7f266ed5294e3c4108"
94259433
integrity sha512-kqBt6vR/5VlCK8iCx1/KpY42kQ+NEHZwsSyt4Y6STiNjU+wWICG1i8ucc1FapXDGO15C5O5VZz7+7vRzrDPXXQ==
@@ -9719,7 +9727,7 @@ pkg-dir@^3.0.0:
97199727
dependencies:
97209728
find-up "^3.0.0"
97219729

9722-
pkginfo@^0.2.3:
9730+
pkginfo@0.2.x, pkginfo@^0.2.3:
97239731
version "0.2.3"
97249732
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.2.3.tgz#7239c42a5ef6c30b8f328439d9b9ff71042490f8"
97259733
integrity sha1-cjnEKl72wwuPMoQ52bn/cQQkkPg=

0 commit comments

Comments
 (0)