mirror of https://github.com/status-im/codimd.git
Merge pull request #1381 from YusukeIwaki/feature/bitbucket_login
Add bitbucket Support
This commit is contained in:
commit
1cf43e1fe2
1
app.js
1
app.js
|
@ -186,6 +186,7 @@ app.locals.authProviders = {
|
||||||
facebook: config.isFacebookEnable,
|
facebook: config.isFacebookEnable,
|
||||||
twitter: config.isTwitterEnable,
|
twitter: config.isTwitterEnable,
|
||||||
github: config.isGitHubEnable,
|
github: config.isGitHubEnable,
|
||||||
|
bitbucket: config.isBitbucketEnable,
|
||||||
gitlab: config.isGitLabEnable,
|
gitlab: config.isGitLabEnable,
|
||||||
mattermost: config.isMattermostEnable,
|
mattermost: config.isMattermostEnable,
|
||||||
dropbox: config.isDropboxEnable,
|
dropbox: config.isDropboxEnable,
|
||||||
|
|
8
app.json
8
app.json
|
@ -80,6 +80,14 @@
|
||||||
"description": "GitHub API client secret",
|
"description": "GitHub API client secret",
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
|
"HMD_BITBUCKET_CLIENTID": {
|
||||||
|
"description": "Bitbucket API client id",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
"HMD_BITBUCKET_CLIENTSECRET": {
|
||||||
|
"description": "Bitbucket API client secret",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
"HMD_GITLAB_BASEURL": {
|
"HMD_GITLAB_BASEURL": {
|
||||||
"description": "GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional)",
|
"description": "GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional)",
|
||||||
"required": false
|
"required": false
|
||||||
|
|
|
@ -70,6 +70,10 @@ module.exports = {
|
||||||
clientID: process.env.CMD_GITHUB_CLIENTID,
|
clientID: process.env.CMD_GITHUB_CLIENTID,
|
||||||
clientSecret: process.env.CMD_GITHUB_CLIENTSECRET
|
clientSecret: process.env.CMD_GITHUB_CLIENTSECRET
|
||||||
},
|
},
|
||||||
|
bitbucket: {
|
||||||
|
clientID: process.env.CMD_BITBUCKET_CLIENTID,
|
||||||
|
clientSecret: process.env.CMD_BITBUCKET_CLIENTSECRET
|
||||||
|
},
|
||||||
gitlab: {
|
gitlab: {
|
||||||
baseURL: process.env.CMD_GITLAB_BASEURL,
|
baseURL: process.env.CMD_GITLAB_BASEURL,
|
||||||
clientID: process.env.CMD_GITLAB_CLIENTID,
|
clientID: process.env.CMD_GITLAB_CLIENTID,
|
||||||
|
|
|
@ -62,6 +62,10 @@ module.exports = {
|
||||||
clientID: process.env.HMD_GITHUB_CLIENTID,
|
clientID: process.env.HMD_GITHUB_CLIENTID,
|
||||||
clientSecret: process.env.HMD_GITHUB_CLIENTSECRET
|
clientSecret: process.env.HMD_GITHUB_CLIENTSECRET
|
||||||
},
|
},
|
||||||
|
bitbucket: {
|
||||||
|
clientID: process.env.HMD_BITBUCKET_CLIENTID,
|
||||||
|
clientSecret: process.env.HMD_BITBUCKET_CLIENTSECRET
|
||||||
|
},
|
||||||
gitlab: {
|
gitlab: {
|
||||||
baseURL: process.env.HMD_GITLAB_BASEURL,
|
baseURL: process.env.HMD_GITLAB_BASEURL,
|
||||||
clientID: process.env.HMD_GITLAB_CLIENTID,
|
clientID: process.env.HMD_GITLAB_CLIENTID,
|
||||||
|
|
|
@ -121,6 +121,7 @@ config.isTwitterEnable = config.twitter.consumerKey && config.twitter.consumerSe
|
||||||
config.isEmailEnable = config.email
|
config.isEmailEnable = config.email
|
||||||
config.isOpenIDEnable = config.openID
|
config.isOpenIDEnable = config.openID
|
||||||
config.isGitHubEnable = config.github.clientID && config.github.clientSecret
|
config.isGitHubEnable = config.github.clientID && config.github.clientSecret
|
||||||
|
config.isBitbucketEnable = config.bitbucket.clientID && config.bitbucket.clientSecret
|
||||||
config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret
|
config.isGitLabEnable = config.gitlab.clientID && config.gitlab.clientSecret
|
||||||
config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret
|
config.isMattermostEnable = config.mattermost.clientID && config.mattermost.clientSecret
|
||||||
config.isLDAPEnable = config.ldap.url
|
config.isLDAPEnable = config.ldap.url
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
'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 + '/'
|
||||||
|
})
|
||||||
|
)
|
|
@ -37,6 +37,7 @@ passport.deserializeUser(function (id, done) {
|
||||||
if (config.isFacebookEnable) authRouter.use(require('./facebook'))
|
if (config.isFacebookEnable) authRouter.use(require('./facebook'))
|
||||||
if (config.isTwitterEnable) authRouter.use(require('./twitter'))
|
if (config.isTwitterEnable) authRouter.use(require('./twitter'))
|
||||||
if (config.isGitHubEnable) authRouter.use(require('./github'))
|
if (config.isGitHubEnable) authRouter.use(require('./github'))
|
||||||
|
if (config.isBitbucketEnable) authRouter.use(require('./bitbucket'))
|
||||||
if (config.isGitLabEnable) authRouter.use(require('./gitlab'))
|
if (config.isGitLabEnable) authRouter.use(require('./gitlab'))
|
||||||
if (config.isMattermostEnable) authRouter.use(require('./mattermost'))
|
if (config.isMattermostEnable) authRouter.use(require('./mattermost'))
|
||||||
if (config.isDropboxEnable) authRouter.use(require('./dropbox'))
|
if (config.isDropboxEnable) authRouter.use(require('./dropbox'))
|
||||||
|
|
|
@ -110,6 +110,7 @@
|
||||||
"passport-dropbox-oauth2": "~1.1.0",
|
"passport-dropbox-oauth2": "~1.1.0",
|
||||||
"passport-facebook": "~2.1.1",
|
"passport-facebook": "~2.1.1",
|
||||||
"passport-github": "~1.1.0",
|
"passport-github": "~1.1.0",
|
||||||
|
"passport-bitbucket-oauth2": "~0.1.2",
|
||||||
"passport-gitlab2": "~4.0.0",
|
"passport-gitlab2": "~4.0.0",
|
||||||
"passport-google-oauth20": "~1.0.0",
|
"passport-google-oauth20": "~1.0.0",
|
||||||
"passport-ldapauth": "~2.1.3",
|
"passport-ldapauth": "~2.1.3",
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<% if (allowAnonymous) { %>
|
<% if (allowAnonymous) { %>
|
||||||
<a type="button" href="<%- serverURL %>/new" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> <%= __('New guest note') %></a>
|
<a type="button" href="<%- serverURL %>/new" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> <%= __('New guest note') %></a>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if (authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.saml || authProviders.oauth2 || authProviders.email) { %>
|
<% 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) { %>
|
||||||
<button class="btn btn-sm btn-success ui-signin" data-toggle="modal" data-target=".signin-modal"><%= __('Sign In') %></button>
|
<button class="btn btn-sm btn-success ui-signin" data-toggle="modal" data-target=".signin-modal"><%= __('Sign In') %></button>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
<% if (errorMessage && errorMessage.length > 0) { %>
|
<% if (errorMessage && errorMessage.length > 0) { %>
|
||||||
<div class="alert alert-danger" style="max-width: 400px; margin: 0 auto;"><%= errorMessage %></div>
|
<div class="alert alert-danger" style="max-width: 400px; margin: 0 auto;"><%= errorMessage %></div>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if (authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.saml || authProviders.oauth2 || authProviders.email) { %>
|
<% 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) { %>
|
||||||
<span class="ui-signin">
|
<span class="ui-signin">
|
||||||
<br>
|
<br>
|
||||||
<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>
|
<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>
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
<i class="fa fa-github"></i> <%= __('Sign in via %s', 'GitHub') %>
|
<i class="fa fa-github"></i> <%= __('Sign in via %s', 'GitHub') %>
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
<% if (authProviders.bitbucket) { %>
|
||||||
|
<a href="<%- serverURL %>/auth/bitbucket" class="btn btn-lg btn-block btn-social btn-bitbucket">
|
||||||
|
<i class="fa fa-bitbucket"></i> <%= __('Sign in via %s', 'Bitbucket') %>
|
||||||
|
</a>
|
||||||
|
<% } %>
|
||||||
<% if (authProviders.gitlab) { %>
|
<% if (authProviders.gitlab) { %>
|
||||||
<a href="<%- serverURL %>/auth/gitlab" class="btn btn-lg btn-block btn-social btn-gitlab">
|
<a href="<%- serverURL %>/auth/gitlab" class="btn btn-lg btn-block btn-social btn-gitlab">
|
||||||
<i class="fa fa-gitlab"></i> <%= __('Sign in via %s', 'GitLab') %>
|
<i class="fa fa-gitlab"></i> <%= __('Sign in via %s', 'GitLab') %>
|
||||||
|
@ -53,7 +58,7 @@
|
||||||
<i class="fa fa-mail-forward"></i> <%= __('Sign in via %s', authProviders.oauth2ProviderName || 'OAuth2') %>
|
<i class="fa fa-mail-forward"></i> <%= __('Sign in via %s', authProviders.oauth2ProviderName || 'OAuth2') %>
|
||||||
</a>
|
</a>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.saml || authProviders.oauth2) && authProviders.ldap) { %>
|
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.bitbucket || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.saml || authProviders.oauth2) && authProviders.ldap) { %>
|
||||||
<hr>
|
<hr>
|
||||||
<% }%>
|
<% }%>
|
||||||
<% if (authProviders.ldap) { %>
|
<% if (authProviders.ldap) { %>
|
||||||
|
@ -78,7 +83,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.oauth2) && authProviders.openID) { %>
|
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.bitbucket || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.oauth2) && authProviders.openID) { %>
|
||||||
<hr>
|
<hr>
|
||||||
<% }%>
|
<% }%>
|
||||||
<% if (authProviders.openID) { %>
|
<% if (authProviders.openID) { %>
|
||||||
|
@ -97,7 +102,7 @@
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<% } %>
|
<% } %>
|
||||||
<% if ((authProviders.facebook || authProviders.twitter || authProviders.github || authProviders.gitlab || authProviders.mattermost || authProviders.dropbox || authProviders.google || authProviders.ldap || authProviders.oauth2 || authProviders.openID) && authProviders.email) { %>
|
<% 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) { %>
|
||||||
<hr>
|
<hr>
|
||||||
<% }%>
|
<% }%>
|
||||||
<% if (authProviders.email) { %>
|
<% if (authProviders.email) { %>
|
||||||
|
|
|
@ -80,6 +80,14 @@
|
||||||
"description": "GitHub API client secret",
|
"description": "GitHub API client secret",
|
||||||
"required": false
|
"required": false
|
||||||
},
|
},
|
||||||
|
"CMD_BITBUCKET_CLIENTID": {
|
||||||
|
"description": "Bitbucket API client id",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
"CMD_BITBUCKET_CLIENTSECRET": {
|
||||||
|
"description": "Bitbucket API client secret",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
"CMD_GITLAB_BASEURL": {
|
"CMD_GITLAB_BASEURL": {
|
||||||
"description": "GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional)",
|
"description": "GitLab authentication endpoint, set to use other endpoint than GitLab.com (optional)",
|
||||||
"required": false
|
"required": false
|
||||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -9357,6 +9357,14 @@ pascalcase@^0.1.1:
|
||||||
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
|
resolved "https://registry.yarnpkg.com/pascalcase/-/pascalcase-0.1.1.tgz#b363e55e8006ca6fe21784d2db22bd15d7917f14"
|
||||||
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=
|
integrity sha1-s2PlXoAGym/iF4TS2yK9FdeRfxQ=
|
||||||
|
|
||||||
|
passport-bitbucket-oauth2@~0.1.2:
|
||||||
|
version "0.1.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/passport-bitbucket-oauth2/-/passport-bitbucket-oauth2-0.1.2.tgz#eb3af5cdd0d06830adc49b76acae4ad82290693b"
|
||||||
|
integrity sha1-6zr1zdDQaDCtxJt2rK5K2CKQaTs=
|
||||||
|
dependencies:
|
||||||
|
passport-oauth2 "^1.1.2"
|
||||||
|
pkginfo "0.2.x"
|
||||||
|
|
||||||
passport-dropbox-oauth2@~1.1.0:
|
passport-dropbox-oauth2@~1.1.0:
|
||||||
version "1.1.0"
|
version "1.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/passport-dropbox-oauth2/-/passport-dropbox-oauth2-1.1.0.tgz#77c737636e4841944dfb82dfc42c3d8ab782c10e"
|
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:
|
||||||
passport-strategy "1.x.x"
|
passport-strategy "1.x.x"
|
||||||
utils-merge "1.x.x"
|
utils-merge "1.x.x"
|
||||||
|
|
||||||
passport-oauth2@1.x.x, passport-oauth2@^1.4.0:
|
passport-oauth2@1.x.x, passport-oauth2@^1.1.2, passport-oauth2@^1.4.0:
|
||||||
version "1.5.0"
|
version "1.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/passport-oauth2/-/passport-oauth2-1.5.0.tgz#64babbb54ac46a4dcab35e7f266ed5294e3c4108"
|
resolved "https://registry.yarnpkg.com/passport-oauth2/-/passport-oauth2-1.5.0.tgz#64babbb54ac46a4dcab35e7f266ed5294e3c4108"
|
||||||
integrity sha512-kqBt6vR/5VlCK8iCx1/KpY42kQ+NEHZwsSyt4Y6STiNjU+wWICG1i8ucc1FapXDGO15C5O5VZz7+7vRzrDPXXQ==
|
integrity sha512-kqBt6vR/5VlCK8iCx1/KpY42kQ+NEHZwsSyt4Y6STiNjU+wWICG1i8ucc1FapXDGO15C5O5VZz7+7vRzrDPXXQ==
|
||||||
|
@ -9719,7 +9727,7 @@ pkg-dir@^3.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
find-up "^3.0.0"
|
find-up "^3.0.0"
|
||||||
|
|
||||||
pkginfo@^0.2.3:
|
pkginfo@0.2.x, pkginfo@^0.2.3:
|
||||||
version "0.2.3"
|
version "0.2.3"
|
||||||
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.2.3.tgz#7239c42a5ef6c30b8f328439d9b9ff71042490f8"
|
resolved "https://registry.yarnpkg.com/pkginfo/-/pkginfo-0.2.3.tgz#7239c42a5ef6c30b8f328439d9b9ff71042490f8"
|
||||||
integrity sha1-cjnEKl72wwuPMoQ52bn/cQQkkPg=
|
integrity sha1-cjnEKl72wwuPMoQ52bn/cQQkkPg=
|
||||||
|
|
Loading…
Reference in New Issue