Skip to content

Commit 1cf43e1

Browse files
authored
Merge pull request #1381 from YusukeIwaki/feature/bitbucket_login
Add bitbucket Support
2 parents 3f089c7 + 12d4aa8 commit 1cf43e1

File tree

12 files changed

+76
-7
lines changed

12 files changed

+76
-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,

app.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@
8080
"description": "GitHub API client secret",
8181
"required": false
8282
},
83+
"HMD_BITBUCKET_CLIENTID": {
84+
"description": "Bitbucket API client id",
85+
"required": false
86+
},
87+
"HMD_BITBUCKET_CLIENTSECRET": {
88+
"description": "Bitbucket API client secret",
89+
"required": false
90+
},
8391
"HMD_GITLAB_BASEURL": {
8492
"description": "GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional)",
8593
"required": false

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/hackmdEnvironment.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ module.exports = {
6262
clientID: process.env.HMD_GITHUB_CLIENTID,
6363
clientSecret: process.env.HMD_GITHUB_CLIENTSECRET
6464
},
65+
bitbucket: {
66+
clientID: process.env.HMD_BITBUCKET_CLIENTID,
67+
clientSecret: process.env.HMD_BITBUCKET_CLIENTSECRET
68+
},
6569
gitlab: {
6670
baseURL: process.env.HMD_GITLAB_BASEURL,
6771
clientID: process.env.HMD_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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
8+
9+
const bitbucketAuth = module.exports = Router()
10+
11+
passport.use(new BitbucketStrategy({
12+
clientID: config.bitbucket.clientID,
13+
clientSecret: config.bitbucket.clientSecret,
14+
callbackURL: config.serverURL + '/auth/bitbucket/callback'
15+
}, passportGeneralCallback))
16+
17+
bitbucketAuth.get('/auth/bitbucket', function (req, res, next) {
18+
setReturnToFromReferer(req)
19+
passport.authenticate('bitbucket')(req, res, next)
20+
})
21+
22+
// bitbucket auth callback
23+
bitbucketAuth.get('/auth/bitbucket/callback',
24+
passport.authenticate('bitbucket', {
25+
successReturnToOrRedirect: config.serverURL + '/',
26+
failureRedirect: config.serverURL + '/'
27+
})
28+
)

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) { %>

0 commit comments

Comments
 (0)