oauth: github: /api

This commit is contained in:
undefined committed 2022-02-09 19:24:20 +08:00
1 parent 67d4f64664
commit 59739e3d86
4 files changed
+8 -7

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "hydrooj",
"version": "3.4.11",
"version": "3.4.12",
"bin": "bin/hydrooj.js",
"main": "src/loader",
"module": "src/loader",
+1 -1
View File
@@ -352,7 +352,7 @@ class OauthHandler extends Handler {
@param('type', Types.String)
async get(domainId: string, type: string) {
if (global.Hydro.lib[`oauth_${type}`]) await global.Hydro.lib[`oauth_${type}`].get.call(this);
await global.Hydro.lib[`oauth_${type}`]?.get?.call(this);
}
}
+5 -4
View File
@@ -15,11 +15,11 @@ declare module 'hydrooj' {
async function get() {
const { system, token } = global.Hydro.model;
const [[appid, endpoint = 'https://github.com'], [state]] = await Promise.all([
system.getMany(['login-with-github.id', 'login-with-github.endpoint']),
const [appid, [state]] = await Promise.all([
system.get('login-with-github.id'),
token.add(token.TYPE_OAUTH, 600, { redirect: this.request.referer }),
]);
this.response.redirect = `${endpoint}/login/oauth/authorize?client_id=${appid}&state=${state}`;
this.response.redirect = `https://github.com/login/oauth/authorize?client_id=${appid}&state=${state}`;
}
async function callback({ state, code }) {
@@ -49,8 +49,9 @@ async function callback({ state, code }) {
);
}
const t = res.body.access_token;
const userInfo = await superagent.get(`${endpoint || 'https://api.github.com'}/user`)
const userInfo = await superagent.get(`${`${endpoint}/api` || 'https://api.github.com'}/user`)
.set('User-Agent', 'Hydro-OAuth')
.set('Accept', 'application/vnd.github.v3+json')
.set('Authorization', `token ${t}`);
const ret = {
_id: `${userInfo.body.id}@github.local`,
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@hydrooj/login-with-github",
"version": "0.1.1",
"version": "0.1.2",
"main": "package.json",
"repository": "git@github.com:hydro-dev/Hydro.git",
"author": "undefined <i@undefined.moe>",