Skip to content

Commit 59c3db3

Browse files
committed
Additional dep
* Partially migrate to newer dep for GH API * Adding some error protection, **but not all**, to the GH API deprecation of QSP's. This is probably temporary until a broader fix is implemented. GH importing may have to be disabled after May 5th, 2021... webhooks might be affected if the old (or new) Promise rejection fails. i.e. no more webhooks... but we'll see after the 5th of next month if not addressed. Applies to OpenUserJS#1705 NOTE(S): * Due to the nature of the dependency with Promises it is currently contrary to the STYLEGUIDE.md See OpenUserJS#1556 as is OpenUserJS#1729 with ES6+ syntax. * Doing what I can to avert this chaos but the Code is spread out all over the place.
1 parent 0e6ec48 commit 59c3db3

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ Repository | Reference | Recent Version
8585
[toobusy-js][toobusy-jsGHUrl] <br />&#x22D4; [`harmony`][toobusy-jsGHUrlHarmonyUrl] | [Documentation][toobusy-jsDOCUrl] | [![NPM version][toobusy-jsNPMVersionImage]][toobusy-jsNPMUrl]
8686
[underscore][underscoreGHUrl] | [Documentation][underscoreDOCUrl] | [![NPM version][underscoreNPMVersionImage]][underscoreNPMUrl]
8787
[useragent][useragentGHUrl] | [Documentation][useragentDOCUrl] | [![NPM version][useragentNPMVersionImage]][useragentNPMUrl]
88+
[@octokit/auth-oauth-app][auth-oauth-appUrl] | [Documentation][auth-oauth-appDOCUrl] | [![NPM version][auth-oauth-appNPMVersionImage]][auth-oauth-appNPMUrl]
8889
[@octokit/rest ᶠᵏᵃ ᵍᶦᵗʰᵘᵇ][githubGHUrl] | [Documentation][githubDOCUrl] | [![NPM version][githubNPMVersionImage]][githubNPMUrl]
8990

90-
9191
##### Static
9292

9393
Repository | Reference | Recent Version | Stored
@@ -478,6 +478,11 @@ Outdated dependencies list can also be achieved with `$ npm outdated`
478478
[squadaOneDOCUrl]: https://github.com/google/fonts/blob/master/README.md
479479
[squadaOneGHUrlRecent]: https://github.com/google/fonts/blob/master/ofl/squadaone/SquadaOne-Regular.ttf
480480

481+
[auth-oauth-appGHUrl]: https://github.com/octokit/auth-oauth-app.js
482+
[auth-oauth-appDOCUrl]: https://github.com/octokit/auth-oauth-app.js/blob/master/README.md
483+
[auth-oauth-appNPMUrl]: https://www.npmjs.com/package/@octokit/auth-oauth-app
484+
[auth-oauth-appNPMVersionImage]: https://img.shields.io/npm/v/@octokit/auth-oauth-app.svg?style=flat
485+
481486
[githubGHUrl]: https://github.com/octokit/rest.js
482487
[githubDOCUrl]: https://github.com/octokit/rest.js/blob/master/README.md
483488
[githubNPMUrl]: https://www.npmjs.com/package/@octokit/rest

libs/githubClient.js

+36-5
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ var isDbg = require('../libs/debug').isDbg;
77
var uaOUJS = require('../libs/debug').uaOUJS;
88

99
//
10-
var GitHubApi = require("github");
1110
var _ = require("underscore");
1211
var async = require('async');
1312
var util = require('util');
1413
var request = require('request');
1514
var colors = require('ansi-colors');
1615

16+
var GitHubApi = require("github");
17+
var createOAuthAppAuth = require("@octokit/auth-oauth-app").createOAuthAppAuth;
18+
1719
// Client
1820
var github = new GitHubApi({
1921
version: "3.0.0"
@@ -22,23 +24,52 @@ module.exports = github;
2224

2325
// Authenticate Client
2426
var Strategy = require('../models/strategy').Strategy;
25-
Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
27+
Strategy.findOne({ name: 'github' }, async function (aErr, aStrat) {
28+
var auth = null;
29+
var appAuthentication = null;
30+
2631
if (aErr)
2732
console.error(aErr);
2833

2934
if (aStrat) {
35+
// This authentication authorization is currently required to authorize this app
36+
// to have the GitHub authentication callback work when the strategy `id` and `key` is found
37+
// and additional usage of the `id` and `key` elsewhere in the Code
38+
39+
auth = createOAuthAppAuth({
40+
clientType: 'oauth-app',
41+
clientId: aStrat.id,
42+
clientSecret: aStrat.key
43+
});
44+
45+
appAuthentication = await auth({
46+
type: "oauth-app"
47+
});
48+
49+
// TODO: Do something with `appAuthentication`
50+
51+
// DEPRECATED: This method will break on May 5th, 2021. See #1705
52+
// and importing a repo will be severely hindered with possible timeouts/failures
3053
github.authenticate({
3154
type: 'oauth',
3255
key: aStrat.id,
33-
secret: aStrat.key,
56+
secret: aStrat.key
3457
});
35-
console.log(colors.green('GitHub client authenticated'));
58+
59+
// TODO: error handler for UnhandledPromiseRejectionWarning if it crops up after deprecation
60+
61+
if (github.auth) {
62+
console.log(colors.green('GitHub client (a.k.a this app) is authenticated'));
63+
} else {
64+
console.log(colors.yellow('GitHub client (a.k.a this app) is partially authenticated'));
65+
}
3666
} else {
37-
console.warn(colors.yellow('GitHub client NOT authenticated. Will have a lower Rate Limit.'));
67+
console.warn(colors.red('GitHub client NOT authenticated. Will have a lower Rate Limit.'));
3868
}
3969

4070
});
4171

72+
4273
// Util functions for the client.
4374
github.usercontent = github.usercontent || {};
4475

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"ace-builds": "1.4.12",
88
"ansi-colors": "4.1.1",
99
"async": "3.2.0",
10+
"@octokit/auth-oauth-app": "4.1.2",
1011
"aws-sdk": "2.879.0",
1112
"base62": "2.0.1",
1213
"body-parser": "1.19.0",

routes.js

+2
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ module.exports = function (aApp) {
136136
aApp.route('/users/:username/comments').get(listLimiter, user.userCommentListPage);
137137
aApp.route('/users/:username/scripts').get(listLimiter, user.userScriptListPage);
138138
aApp.route('/users/:username/syncs').get(listLimiter, user.userSyncListPage);
139+
139140
aApp.route('/users/:username/github/repos').get(authentication.validateUser, user.userGitHubRepoListPage);
140141
aApp.route('/users/:username/github/repo').get(authentication.validateUser, user.userGitHubRepoPage);
141142
aApp.route('/users/:username/github/import').post(authentication.validateUser, user.userGitHubImportScriptPage);
143+
142144
aApp.route('/users/:username/profile/edit').get(authentication.validateUser, user.userEditProfilePage).post(authentication.validateUser, user.update);
143145
aApp.route('/users/:username/update').post(authentication.validateUser, admin.adminUserUpdate);
144146
// NOTE: Some below inconsistent with priors

0 commit comments

Comments
 (0)