-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
almost working oauth except for 500 ERROR AGHGHJGHGH
- Loading branch information
1 parent
38f24a2
commit 3b136df
Showing
6 changed files
with
126 additions
and
2 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,34 @@ | ||
module.exports = (app, utils) => { | ||
app.get("/api/v1/users/oauthlogin", async function (req, res) { | ||
const packet = req.query; | ||
|
||
const state = packet.state; | ||
const code = packet.code; | ||
|
||
if (!state || !code) { | ||
utils.error(res, 400, "InvalidData"); | ||
return; | ||
} | ||
|
||
if (!await utils.UserManager.verifyOAuth2State(state)) { | ||
utils.error(res, 400, "InvalidData"); | ||
return; | ||
} | ||
|
||
// now make the request | ||
const response = await utils.UserManager.makeOAuth2Request(code, "scratch"); | ||
|
||
console.log(response.access_token); | ||
|
||
const username = await fetch("https://oauth2.scratch-wiki.info/w/rest.php/soa2/v0/user", { | ||
headers: { | ||
Authorization: `Bearer ${btoa(response.access_token)}` | ||
} | ||
}).then(res => res.status); | ||
|
||
console.log(username); | ||
|
||
res.status(200); | ||
res.send("hi"); | ||
}); | ||
} |
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,24 @@ | ||
module.exports = (app, utils) => { | ||
app.get("/api/v1/users/oauth", async function (req, res) { | ||
// get the method | ||
const packet = req.query; | ||
|
||
const method = packet.method; | ||
|
||
if (!method) { | ||
utils.error(res, 400, "InvalidData"); | ||
return; | ||
} | ||
|
||
// using switch case cuz erm i like it | ||
switch (method) { | ||
case "scratch": | ||
let state = await utils.UserManager.generateOAuth2State(); | ||
res.redirect(`https://oauth2.scratch-wiki.info/wiki/Special:ScratchOAuth2/authorize?client_id=${utils.env.ScratchOauth2ClientID}&redirect_uri=https://projects.penguinmod.com/api/v1/users/oauthlogin&scopes=identify&state=${state}`); | ||
break; | ||
default: | ||
utils.error(res, 400, "InvalidData"); | ||
return; | ||
} | ||
}); | ||
} |
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,24 @@ | ||
module.exports = (app, utils) => { | ||
app.get("/api/v1/users/oauthlocal", async function (req, res) { | ||
// get the method | ||
const packet = req.query; | ||
|
||
const method = packet.method; | ||
|
||
if (!method) { | ||
utils.error(res, 400, "InvalidData"); | ||
return; | ||
} | ||
|
||
// using switch case cuz erm i like it | ||
switch (method) { | ||
case "scratch": | ||
let state = await utils.UserManager.generateOAuth2State(); | ||
res.redirect(`https://oauth2.scratch-wiki.info/wiki/Special:ScratchOAuth2/authorize?client_id=${utils.env.ScratchOauth2ClientID}&redirect_uri=http://localhost:8080/api/v1/users/oauthlogin&scopes=identify&state=${state}`); | ||
break; | ||
default: | ||
utils.error(res, 400, "InvalidData"); | ||
return; | ||
} | ||
}); | ||
} |
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