Skip to content

Commit

Permalink
fix: skland generate cred by code
Browse files Browse the repository at this point in the history
fix #281
  • Loading branch information
Tsuk1ko committed Sep 26, 2024
1 parent 16e3fcc commit a1f6318
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions src/utils/skland.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export async function fetchSkland(path, cred, token, body) {
}
: {}),
headers: {
Cred: cred,
...(cred ? { Cred: cred } : {}),
...(await sign(path, token)),
...(body ? { 'Content-Type': 'application/json' } : {}),
},
Expand All @@ -87,10 +87,12 @@ export async function fetchSkland(path, cred, token, body) {
}
}

async function fetchSklandOAuthCode(token) {
if (!PROXY_SERVER) throw new Error('No proxy server.');

const res = await fetch(`${PROXY_SERVER}/as.hypergryph.com/user/oauth2/v2/grant`, {
/**
* @param {string} token
* @returns {{ cred: string, token: string }}
*/
export async function sklandOAuthLogin(token) {
const res = await fetch(`${PROXY_SERVER}/skland/oauth_combine`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -100,26 +102,13 @@ async function fetchSklandOAuthCode(token) {

const data = await res.json();

if (data.status === 0) {
if (data.code === 0) {
return data.data;
} else {
throw new SklandError(data.msg, data.status);
throw new SklandError(data.message, data.code);
}
}

/**
* @param {string} token
* @returns {{ cred: string, token: string }}
*/
export async function sklandOAuthLogin(token) {
const { code } = await fetchSklandOAuthCode(token);

return await fetchSkland('/api/v1/user/auth/generate_cred_by_code', undefined, undefined, {
code,
kind: 1,
});
}

/**
* @param {SklandError} err
*/
Expand Down

0 comments on commit a1f6318

Please sign in to comment.