Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GitHub Enterprise OAuth. #1614

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions server/conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const dropboxAppKey = process.env.DROPBOX_APP_KEY;
const dropboxAppKeyFull = process.env.DROPBOX_APP_KEY_FULL;
const githubClientId = process.env.GITHUB_CLIENT_ID;
const githubClientSecret = process.env.GITHUB_CLIENT_SECRET;
const githubAuthUrl = process.env.GITHUB_AUTH_URL || 'https://github.com/login/oauth/authorize';
const githubTokenUrl = process.env.GITHUB_TOKEN_URL || 'https://github.com/login/oauth/access_token';
const githubUserProfileUrl = process.env.GITHUB_USER_PROFILE_URL || 'https://api.github.com/user';
const googleClientId = process.env.GOOGLE_CLIENT_ID;
const googleApiKey = process.env.GOOGLE_API_KEY;
const wordpressClientId = process.env.WORDPRESS_CLIENT_ID;
Expand All @@ -22,6 +25,9 @@ exports.values = {
dropboxAppKeyFull,
githubClientId,
githubClientSecret,
githubAuthUrl,
githubTokenUrl,
githubUserProfileUrl,
googleClientId,
googleApiKey,
wordpressClientId,
Expand All @@ -31,6 +37,9 @@ exports.publicValues = {
dropboxAppKey,
dropboxAppKeyFull,
githubClientId,
githubAuthUrl,
githubTokenUrl,
githubUserProfileUrl,
googleClientId,
googleApiKey,
wordpressClientId,
Expand Down
2 changes: 1 addition & 1 deletion server/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function githubToken(clientId, code) {
return new Promise((resolve, reject) => {
request({
method: 'POST',
url: 'https://github.com/login/oauth/access_token',
url: conf.values.githubTokenUrl,
qs: {
client_id: clientId,
client_secret: conf.values.githubClientSecret,
Expand Down
10 changes: 3 additions & 7 deletions src/data/defaults/defaultSettings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,13 @@ turndown:

# GitHub/GitLab commit messages
git:
createFileMessage: '{{path}} created from https://stackedit.io/'
updateFileMessage: '{{path}} updated from https://stackedit.io/'
deleteFileMessage: '{{path}} deleted from https://stackedit.io/'
createFileMessage: '{{path}} created'
updateFileMessage: '{{path}} updated'
deleteFileMessage: '{{path}} deleted'

# Default content for new files
newFileContent: |



> Written with [StackEdit](https://stackedit.io/).

# Default properties for new files
newFileProperties: |
# extensions:
Expand Down
6 changes: 4 additions & 2 deletions src/services/providers/helpers/githubHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ export default {
* https://developer.github.com/apps/building-oauth-apps/authorization-options-for-oauth-apps/
*/
async startOauth2(scopes, sub = null, silent = false) {
const githubAuthUrl = store.getters['data/serverConf'].githubAuthUrl;
const githubUserProfileUrl = store.getters['data/serverConf'].githubUserProfileUrl;
const clientId = store.getters['data/serverConf'].githubClientId;

// Get an OAuth2 code
const { code } = await networkSvc.startOauth2(
'https://github.com/login/oauth/authorize',
githubAuthUrl,
{
client_id: clientId,
scope: scopes.join(' '),
Expand All @@ -88,7 +90,7 @@ export default {
// Call the user info endpoint
const user = (await networkSvc.request({
method: 'GET',
url: 'https://api.github.com/user',
url: githubUserProfileUrl,
params: {
access_token: accessToken,
},
Expand Down
2 changes: 1 addition & 1 deletion src/store/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default {
Object.entries(rootGetters['data/workspaces']).forEach(([id, workspace]) => {
const sanitizedWorkspace = {
id,
providerId: 'googleDriveAppData',
providerId: 'githubWorkspace',
sub: mainWorkspaceToken && mainWorkspaceToken.sub,
...workspace,
};
Expand Down