mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
oauth: github: /api
This commit is contained in:
1 parent
67d4f64664
commit
59739e3d86
4 files changed
+8
-7
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "3.4.11",
|
"version": "3.4.12",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "src/loader",
|
"main": "src/loader",
|
||||||
"module": "src/loader",
|
"module": "src/loader",
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ class OauthHandler extends Handler {
|
|||||||
|
|
||||||
@param('type', Types.String)
|
@param('type', Types.String)
|
||||||
async get(domainId: string, type: 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ declare module 'hydrooj' {
|
|||||||
|
|
||||||
async function get() {
|
async function get() {
|
||||||
const { system, token } = global.Hydro.model;
|
const { system, token } = global.Hydro.model;
|
||||||
const [[appid, endpoint = 'https://github.com'], [state]] = await Promise.all([
|
const [appid, [state]] = await Promise.all([
|
||||||
system.getMany(['login-with-github.id', 'login-with-github.endpoint']),
|
system.get('login-with-github.id'),
|
||||||
token.add(token.TYPE_OAUTH, 600, { redirect: this.request.referer }),
|
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 }) {
|
async function callback({ state, code }) {
|
||||||
@@ -49,8 +49,9 @@ async function callback({ state, code }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
const t = res.body.access_token;
|
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('User-Agent', 'Hydro-OAuth')
|
||||||
|
.set('Accept', 'application/vnd.github.v3+json')
|
||||||
.set('Authorization', `token ${t}`);
|
.set('Authorization', `token ${t}`);
|
||||||
const ret = {
|
const ret = {
|
||||||
_id: `${userInfo.body.id}@github.local`,
|
_id: `${userInfo.body.id}@github.local`,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/login-with-github",
|
"name": "@hydrooj/login-with-github",
|
||||||
"version": "0.1.1",
|
"version": "0.1.2",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"repository": "git@github.com:hydro-dev/Hydro.git",
|
"repository": "git@github.com:hydro-dev/Hydro.git",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
|
|||||||
Reference in new issue
Block a user