Skip to content

Commit

Permalink
code cleanup: remove client id and secret (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingyan authored Mar 23, 2021
1 parent 395fdaa commit f191d67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 31 deletions.
8 changes: 4 additions & 4 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"devtest"
],
"dependencies": {
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/preset-react": "^7.12.13",
"@babel/register": "^7.13.8",
"async": "^1.0.0",
"body-parser": "^1.6.4",
"classnames": "^2.1.3",
Expand All @@ -42,10 +46,6 @@
"superagent": "^3.8.3"
},
"devDependencies": {
"@babel/core": "^7.13.10",
"@babel/preset-env": "^7.13.10",
"@babel/preset-react": "^7.12.13",
"@babel/register": "^7.13.8",
"babel-eslint": "^10.0.0",
"babel-loader": "^8.2.2",
"chai": "^3.0.0",
Expand Down
14 changes: 4 additions & 10 deletions site/secrets.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
/**
* This is a sample file for your Github client id and client secret
* This is needed to collect the doc's from the fluxible repo.
* You can generate the client/secret pair here: https://github.com/settings/applications/new
* This is a sample file for using your Github access token to collect
* the doc's from the fluxible repo.
*
* Alternatively, you can pass in an oauth access token to work around the rate limiting
* restrictions of the client id / secret pair
*
* GitHub Auth docs: https://developer.github.com/v3/#authentication
* GitHub Auth docs: https://docs.github.com/en/rest/overview/resources-in-the-rest-api#authentication
*/
export default {
github: {
accessToken: process.env.GITHUB_ACCESS_TOKEN || '',
clientId: process.env.GITHUB_CLIENT_ID || '',
clientSecret: process.env.GITHUB_CLIENT_SECRET || ''
accessToken: process.env.GITHUB_ACCESS_TOKEN || ''
}
};
24 changes: 7 additions & 17 deletions site/services/docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ marked.setOptions({
}
});

if (secrets.github.accessToken) {
console.log('All good! Found access token.');
} else {
console.error('Not good! Missing access token. Will be rate-limited by github API.');
}

// Generate a hash of valid api routes, from the /configs/apis.js file
let cache = {};
let documents = {};
Expand Down Expand Up @@ -58,22 +64,6 @@ function fetchGitHubReposApi(params, cb) {
// create github api url
let githubUrl = 'https://api.github.com/repos/' + repo + '/' + type + '?';

// use access token if available, otherwise use client id and secret
if (secrets.github.accessToken) {
// using accessToken as query param is being deprecated
// https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param/
// githubUrl += qs.stringify({
// access_token: secrets.github.accessToken
// });
} else {
// using clientId and clientSecret as query param is being deprecated as well.
// will remove this after switching fluxible.io to use accessToken.
githubUrl += qs.stringify({
client_id: secrets.github.clientId,
client_secret: secrets.github.clientSecret
});
}

// the name of the commit/branch/tag
if (params.ref) {
githubUrl += '&ref=' + params.ref;
Expand All @@ -87,7 +77,7 @@ function fetchGitHubReposApi(params, cb) {
.set('Authorization', 'token ' + secrets.github.accessToken)
.end(cb);
} else {
// will remove this after switching fluxible.io to use accessToken.
// still make call to github API, but will be rate limited.
request
.get(githubUrl)
.set('User-Agent', 'superagent')
Expand Down

0 comments on commit f191d67

Please sign in to comment.