-
Notifications
You must be signed in to change notification settings - Fork 875
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from conwnet/master
release 0.4.0
- Loading branch information
Showing
39 changed files
with
3,469 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* @file github auth callback | ||
* @author netcon | ||
*/ | ||
|
||
const got = require('got'); | ||
|
||
const CLIENT_ID = process.env.GITHUB_OAUTH_ID || ''; | ||
const CLIENT_SECRET = process.env.GITHUB_OAUTH_SECRET || ''; | ||
// allow origins should split by ',' | ||
const ALLOWED_ORIGINS = process.env.ALLOWED_ORIGINS || ''; | ||
|
||
// return the data to the opener window by postMessage API, | ||
// and close current window then | ||
const getResponseHtml = (dataStr) => ` | ||
<script> | ||
'${ALLOWED_ORIGINS}'.split(',').forEach(function(allowedOrigin) { | ||
window.opener.postMessage(${dataStr}, allowedOrigin); | ||
}); | ||
setTimeout(() => window.close(), 50); | ||
</script> | ||
`; | ||
|
||
const MISSING_CODE_ERROR = { | ||
error: 'request_invalid', | ||
error_description: 'Missing code', | ||
}; | ||
const UNKNOWN_ERROR = { | ||
error: 'internal_error', | ||
error_description: 'Unknown error', | ||
}; | ||
|
||
module.exports = async (req, res) => { | ||
const code = req.query.code; | ||
const sendResponseHtml = (status, data) => { | ||
res.status(status); | ||
const responseData = { type: 'authorizing', payload: data }; | ||
res.send(getResponseHtml(JSON.stringify(responseData))); | ||
}; | ||
|
||
if (!code) { | ||
return sendResponseHtml(401, MISSING_CODE_ERROR); | ||
} | ||
|
||
try { | ||
// https://docs.github.com/en/developers/apps/authorizing-oauth-apps#2-users-are-redirected-back-to-your-site-by-github | ||
const response = await got.post( | ||
'https://github.com/login/oauth/access_token', | ||
{ | ||
json: { client_id: CLIENT_ID, client_secret: CLIENT_SECRET, code }, | ||
responseType: 'json', | ||
} | ||
); | ||
return sendResponseHtml(response.statusCode, response.body); | ||
} catch (e) { | ||
// the error is responded by GitHub | ||
if (e.response) { | ||
return sendResponseHtml(e.response.statusCode, e.response.body); | ||
} | ||
return sendResponseHtml(500, UNKNOWN_ERROR); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "github-auth-callback", | ||
"version": "0.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"private": true, | ||
"dependencies": { | ||
"got": "^11.8.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,204 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
"@sindresorhus/is@^4.0.0": | ||
version "4.0.1" | ||
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.0.1.tgz#d26729db850fa327b7cacc5522252194404226f5" | ||
integrity sha512-Qm9hBEBu18wt1PO2flE7LPb30BHMQt1eQgbV76YntdNk73XZGpn3izvGTYxbGgzXKgbCjiia0uxTd3aTNQrY/g== | ||
|
||
"@szmarczak/http-timer@^4.0.5": | ||
version "4.0.5" | ||
resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-4.0.5.tgz#bfbd50211e9dfa51ba07da58a14cdfd333205152" | ||
integrity sha512-PyRA9sm1Yayuj5OIoJ1hGt2YISX45w9WcFbh6ddT0Z/0yaFxOtGLInr4jUfU1EAFVs0Yfyfev4RNwBlUaHdlDQ== | ||
dependencies: | ||
defer-to-connect "^2.0.0" | ||
|
||
"@types/cacheable-request@^6.0.1": | ||
version "6.0.1" | ||
resolved "https://registry.yarnpkg.com/@types/cacheable-request/-/cacheable-request-6.0.1.tgz#5d22f3dded1fd3a84c0bbeb5039a7419c2c91976" | ||
integrity sha512-ykFq2zmBGOCbpIXtoVbz4SKY5QriWPh3AjyU4G74RYbtt5yOc5OfaY75ftjg7mikMOla1CTGpX3lLbuJh8DTrQ== | ||
dependencies: | ||
"@types/http-cache-semantics" "*" | ||
"@types/keyv" "*" | ||
"@types/node" "*" | ||
"@types/responselike" "*" | ||
|
||
"@types/http-cache-semantics@*": | ||
version "4.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/http-cache-semantics/-/http-cache-semantics-4.0.0.tgz#9140779736aa2655635ee756e2467d787cfe8a2a" | ||
integrity sha512-c3Xy026kOF7QOTn00hbIllV1dLR9hG9NkSrLQgCVs8NF6sBU+VGWjD3wLPhmh1TYAc7ugCFsvHYMN4VcBN1U1A== | ||
|
||
"@types/keyv@*": | ||
version "3.1.1" | ||
resolved "https://registry.yarnpkg.com/@types/keyv/-/keyv-3.1.1.tgz#e45a45324fca9dab716ab1230ee249c9fb52cfa7" | ||
integrity sha512-MPtoySlAZQ37VoLaPcTHCu1RWJ4llDkULYZIzOYxlhxBqYPB0RsRlmMU0R6tahtFe27mIdkHV+551ZWV4PLmVw== | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
"@types/node@*": | ||
version "15.0.2" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.0.2.tgz#51e9c0920d1b45936ea04341aa3e2e58d339fb67" | ||
integrity sha512-p68+a+KoxpoB47015IeYZYRrdqMUcpbK8re/zpFB8Ld46LHC1lPEbp3EXgkEhAYEcPvjJF6ZO+869SQ0aH1dcA== | ||
|
||
"@types/responselike@*", "@types/responselike@^1.0.0": | ||
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29" | ||
integrity sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA== | ||
dependencies: | ||
"@types/node" "*" | ||
|
||
cacheable-lookup@^5.0.3: | ||
version "5.0.4" | ||
resolved "https://registry.yarnpkg.com/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz#5a6b865b2c44357be3d5ebc2a467b032719a7005" | ||
integrity sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA== | ||
|
||
cacheable-request@^7.0.1: | ||
version "7.0.1" | ||
resolved "https://registry.yarnpkg.com/cacheable-request/-/cacheable-request-7.0.1.tgz#062031c2856232782ed694a257fa35da93942a58" | ||
integrity sha512-lt0mJ6YAnsrBErpTMWeu5kl/tg9xMAWjavYTN6VQXM1A/teBITuNcccXsCxF0tDQQJf9DfAaX5O4e0zp0KlfZw== | ||
dependencies: | ||
clone-response "^1.0.2" | ||
get-stream "^5.1.0" | ||
http-cache-semantics "^4.0.0" | ||
keyv "^4.0.0" | ||
lowercase-keys "^2.0.0" | ||
normalize-url "^4.1.0" | ||
responselike "^2.0.0" | ||
|
||
clone-response@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/clone-response/-/clone-response-1.0.2.tgz#d1dc973920314df67fbeb94223b4ee350239e96b" | ||
integrity sha1-0dyXOSAxTfZ/vrlCI7TuNQI56Ws= | ||
dependencies: | ||
mimic-response "^1.0.0" | ||
|
||
decompress-response@^6.0.0: | ||
version "6.0.0" | ||
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-6.0.0.tgz#ca387612ddb7e104bd16d85aab00d5ecf09c66fc" | ||
integrity sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ== | ||
dependencies: | ||
mimic-response "^3.1.0" | ||
|
||
defer-to-connect@^2.0.0: | ||
version "2.0.1" | ||
resolved "https://registry.yarnpkg.com/defer-to-connect/-/defer-to-connect-2.0.1.tgz#8016bdb4143e4632b77a3449c6236277de520587" | ||
integrity sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg== | ||
|
||
end-of-stream@^1.1.0: | ||
version "1.4.4" | ||
resolved "https://registry.yarnpkg.com/end-of-stream/-/end-of-stream-1.4.4.tgz#5ae64a5f45057baf3626ec14da0ca5e4b2431eb0" | ||
integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q== | ||
dependencies: | ||
once "^1.4.0" | ||
|
||
get-stream@^5.1.0: | ||
version "5.2.0" | ||
resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-5.2.0.tgz#4966a1795ee5ace65e706c4b7beb71257d6e22d3" | ||
integrity sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA== | ||
dependencies: | ||
pump "^3.0.0" | ||
|
||
got@^11.8.2: | ||
version "11.8.2" | ||
resolved "https://registry.yarnpkg.com/got/-/got-11.8.2.tgz#7abb3959ea28c31f3576f1576c1effce23f33599" | ||
integrity sha512-D0QywKgIe30ODs+fm8wMZiAcZjypcCodPNuMz5H9Mny7RJ+IjJ10BdmGW7OM7fHXP+O7r6ZwapQ/YQmMSvB0UQ== | ||
dependencies: | ||
"@sindresorhus/is" "^4.0.0" | ||
"@szmarczak/http-timer" "^4.0.5" | ||
"@types/cacheable-request" "^6.0.1" | ||
"@types/responselike" "^1.0.0" | ||
cacheable-lookup "^5.0.3" | ||
cacheable-request "^7.0.1" | ||
decompress-response "^6.0.0" | ||
http2-wrapper "^1.0.0-beta.5.2" | ||
lowercase-keys "^2.0.0" | ||
p-cancelable "^2.0.0" | ||
responselike "^2.0.0" | ||
|
||
http-cache-semantics@^4.0.0: | ||
version "4.1.0" | ||
resolved "https://registry.yarnpkg.com/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz#49e91c5cbf36c9b94bcfcd71c23d5249ec74e390" | ||
integrity sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ== | ||
|
||
http2-wrapper@^1.0.0-beta.5.2: | ||
version "1.0.3" | ||
resolved "https://registry.yarnpkg.com/http2-wrapper/-/http2-wrapper-1.0.3.tgz#b8f55e0c1f25d4ebd08b3b0c2c079f9590800b3d" | ||
integrity sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg== | ||
dependencies: | ||
quick-lru "^5.1.1" | ||
resolve-alpn "^1.0.0" | ||
|
||
[email protected]: | ||
version "3.0.1" | ||
resolved "https://registry.yarnpkg.com/json-buffer/-/json-buffer-3.0.1.tgz#9338802a30d3b6605fbe0613e094008ca8c05a13" | ||
integrity sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ== | ||
|
||
keyv@^4.0.0: | ||
version "4.0.3" | ||
resolved "https://registry.yarnpkg.com/keyv/-/keyv-4.0.3.tgz#4f3aa98de254803cafcd2896734108daa35e4254" | ||
integrity sha512-zdGa2TOpSZPq5mU6iowDARnMBZgtCqJ11dJROFi6tg6kTn4nuUdU09lFyLFSaHrWqpIJ+EBq4E8/Dc0Vx5vLdA== | ||
dependencies: | ||
json-buffer "3.0.1" | ||
|
||
lowercase-keys@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-2.0.0.tgz#2603e78b7b4b0006cbca2fbcc8a3202558ac9479" | ||
integrity sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA== | ||
|
||
mimic-response@^1.0.0: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-1.0.1.tgz#4923538878eef42063cb8a3e3b0798781487ab1b" | ||
integrity sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ== | ||
|
||
mimic-response@^3.1.0: | ||
version "3.1.0" | ||
resolved "https://registry.yarnpkg.com/mimic-response/-/mimic-response-3.1.0.tgz#2d1d59af9c1b129815accc2c46a022a5ce1fa3c9" | ||
integrity sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ== | ||
|
||
normalize-url@^4.1.0: | ||
version "4.5.0" | ||
resolved "https://registry.yarnpkg.com/normalize-url/-/normalize-url-4.5.0.tgz#453354087e6ca96957bd8f5baf753f5982142129" | ||
integrity sha512-2s47yzUxdexf1OhyRi4Em83iQk0aPvwTddtFz4hnSSw9dCEsLEGf6SwIO8ss/19S9iBb5sJaOuTvTGDeZI00BQ== | ||
|
||
once@^1.3.1, once@^1.4.0: | ||
version "1.4.0" | ||
resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" | ||
integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= | ||
dependencies: | ||
wrappy "1" | ||
|
||
p-cancelable@^2.0.0: | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-2.1.1.tgz#aab7fbd416582fa32a3db49859c122487c5ed2cf" | ||
integrity sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg== | ||
|
||
pump@^3.0.0: | ||
version "3.0.0" | ||
resolved "https://registry.yarnpkg.com/pump/-/pump-3.0.0.tgz#b4a2116815bde2f4e1ea602354e8c75565107a64" | ||
integrity sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww== | ||
dependencies: | ||
end-of-stream "^1.1.0" | ||
once "^1.3.1" | ||
|
||
quick-lru@^5.1.1: | ||
version "5.1.1" | ||
resolved "https://registry.yarnpkg.com/quick-lru/-/quick-lru-5.1.1.tgz#366493e6b3e42a3a6885e2e99d18f80fb7a8c932" | ||
integrity sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA== | ||
|
||
resolve-alpn@^1.0.0: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/resolve-alpn/-/resolve-alpn-1.1.2.tgz#30b60cfbb0c0b8dc897940fe13fe255afcdd4d28" | ||
integrity sha512-8OyfzhAtA32LVUsJSke3auIyINcwdh5l3cvYKdKO0nvsYSKuiLfTM5i78PJswFPT8y6cPW+L1v6/hE95chcpDA== | ||
|
||
responselike@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/responselike/-/responselike-2.0.0.tgz#26391bcc3174f750f9a79eacc40a12a5c42d7723" | ||
integrity sha512-xH48u3FTB9VsZw7R+vvgaKeLKzT6jOogbQhEe/jewwnZgzPcnyWui2Av6JpoYZF/91uueC+lqhWqeURw5/qhCw== | ||
dependencies: | ||
lowercase-keys "^2.0.0" | ||
|
||
wrappy@1: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" | ||
integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @file static files not found fallback | ||
* According to the config in vercel.json, we cached the | ||
* static files with `max-age=X` header, but we may get 404 | ||
* response durning deploying, the default behavior for vercel | ||
* would add the cache header to this 404 response, which caused | ||
* the user can not get right resources anymore. so we should | ||
* fallback to here and clear the cache header for such 404 requests. | ||
* See also: https://github.com/conwnet/github1s/issues/299 | ||
* @author netcon | ||
*/ | ||
|
||
module.exports = async (req, res) => { | ||
res.status(404); | ||
res.setHeader('Cache-Control', 'no-store'); | ||
res.send('Not Found'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
f5e74c1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: