Skip to content

Commit 78e6663

Browse files
authored
Merge pull request #1835 from hackmdio/release/2.5.0
Release 2.5.0
2 parents 5d84066 + afe49f4 commit 78e6663

34 files changed

+4013
-2415
lines changed

.buildpacks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
https://github.com/alex88/heroku-buildpack-vips
1+
https://github.com/Scalingo/apt-buildpack
22
https://github.com/Scalingo/nodejs-buildpack

.devcontainer/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# [Choice] Node.js version: 16, 14, 12
2-
ARG VARIANT=12-buster
1+
# [Choice] Node.js version: 16, 14
2+
ARG VARIANT=14-buster
33
FROM mcr.microsoft.com/vscode/devcontainers/javascript-node:0-${VARIANT}
44

55
# [Optional] Uncomment this section to install additional OS packages.

.devcontainer/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
context: ..
77
dockerfile: .devcontainer/Dockerfile
88
args:
9-
VARIANT: 12-buster
9+
VARIANT: 14-buster
1010
environment:
1111
- CMD_DB_URL=postgres://codimd:codimd@localhost/codimd
1212
- CMD_USECDN=false

.github/workflows/build.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
node-version: [10.x, 12.x]
13+
node-version: [14.x, 16.x]
1414

1515
steps:
1616
- uses: actions/checkout@v2
@@ -39,9 +39,9 @@ jobs:
3939
steps:
4040
- uses: actions/checkout@v2
4141
- uses: actions/setup-node@v2
42-
name: Use Node.js 12
42+
name: Use Node.js 14
4343
with:
44-
node-version: 12
44+
node-version: 14
4545
check-latest: true
4646
- name: Install doctoc-check
4747
run: |

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v10.20.1
1+
v16.20.2

Aptfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
libvips-dev

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ CodiMD is a service that runs on Node.js, while users use the service through br
8181
- <img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/chrome/chrome_48x48.png" alt="Chrome" width="24px" height="24px" /> Chrome >= 47, Chrome for Android >= 47
8282
- <img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/safari/safari_48x48.png" alt="Safari" width="24px" height="24px" /> Safari >= 9, iOS Safari >= 8.4
8383
- <img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/firefox/firefox_48x48.png" alt="Firefox" width="24px" height="24px" /> Firefox >= 44
84-
- <img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="IE / Edge" width="24px" height="24px" /> IE >= 9, Edge >= 12
84+
- <img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/edge/edge_48x48.png" alt="Edge" width="24px" height="24px" /> Edge >= 12
8585
- <img src="https://raw.githubusercontent.com/alrra/browser-logos/master/src/opera/opera_48x48.png" alt="Opera" width="24px" height="24px" /> Opera >= 34, Opera Mini not supported
8686
- Android Browser >= 4.4
8787

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+
"CMD_GITHUB_ORGANIZATIONS": {
84+
"description": "GitHub whitelist of orgs",
85+
"required": false
86+
},
87+
"CMD_GITHUB_SCOPES": {
88+
"description": "GitHub OAuth API scopes",
89+
"required": false
90+
},
8391
"CMD_BITBUCKET_CLIENTID": {
8492
"description": "Bitbucket API client id",
8593
"required": false

config.json.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@
5353
},
5454
"github": {
5555
"clientID": "change this",
56-
"clientSecret": "change this"
56+
"clientSecret": "change this",
57+
"organizations": ["names of github organizations allowed, optional"],
58+
"scopes": ["defaults to 'read:user' scope for auth user"]
5759
},
5860
"gitlab": {
5961
"baseURL": "change this",

lib/auth/github/index.js

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
'use strict'
22

33
const Router = require('express').Router
4+
const request = require('request')
45
const passport = require('passport')
56
const GithubStrategy = require('passport-github').Strategy
7+
const { InternalOAuthError } = require('passport-oauth2')
68
const config = require('../../config')
79
const response = require('../../response')
810
const { setReturnToFromReferer, passportGeneralCallback } = require('../utils')
911
const { URL } = require('url')
12+
const { promisify } = require('util')
13+
14+
const rp = promisify(request)
1015

1116
const githubAuth = module.exports = Router()
1217

@@ -15,20 +20,48 @@ function githubUrl (path) {
1520
}
1621

1722
passport.use(new GithubStrategy({
23+
scope: (config.github.organizations ? config.github.scopes.concat(['read:org']) : config.github.scope),
1824
clientID: config.github.clientID,
1925
clientSecret: config.github.clientSecret,
2026
callbackURL: config.serverURL + '/auth/github/callback',
2127
authorizationURL: githubUrl('login/oauth/authorize'),
2228
tokenURL: githubUrl('login/oauth/access_token'),
2329
userProfileURL: githubUrl('api/v3/user')
24-
}, passportGeneralCallback))
30+
}, async (accessToken, refreshToken, profile, done) => {
31+
if (!config.github.organizations) {
32+
return passportGeneralCallback(accessToken, refreshToken, profile, done)
33+
}
34+
const { statusCode, body: data } = await rp({
35+
url: `https://api.github.com/user/orgs`,
36+
method: 'GET',
37+
json: true,
38+
timeout: 2000,
39+
headers: {
40+
Authorization: `token ${accessToken}`,
41+
'User-Agent': 'nodejs-http'
42+
}
43+
})
44+
if (statusCode !== 200) {
45+
return done(InternalOAuthError(
46+
`Failed to query organizations for user: ${profile.username}`
47+
))
48+
}
49+
const orgs = data.map(({ login }) => login)
50+
for (const org of orgs) {
51+
if (config.github.organizations.includes(org)) {
52+
return passportGeneralCallback(accessToken, refreshToken, profile, done)
53+
}
54+
}
55+
return done(InternalOAuthError(
56+
`User orgs not whitelisted: ${profile.username} (${orgs.join(',')})`
57+
))
58+
}))
2559

2660
githubAuth.get('/auth/github', function (req, res, next) {
2761
setReturnToFromReferer(req)
2862
passport.authenticate('github')(req, res, next)
2963
})
3064

31-
// github auth callback
3265
githubAuth.get('/auth/github/callback',
3366
passport.authenticate('github', {
3467
successReturnToOrRedirect: config.serverURL + '/',

0 commit comments

Comments
 (0)