add custome callback port

This commit is contained in:
2024-01-10 02:37:41 +01:00
parent 9d82dea4e1
commit f6a2759e7e
2 changed files with 10 additions and 3 deletions

View File

@@ -7,6 +7,6 @@
</head> </head>
<body> <body>
<p>Hey u shouldnt be here!</p> <p>Hey u shouldnt be here!</p>
<a href='/authorize' target="_blank">Login with Osu!</a> <a href='/authorize?4200' target="_blank">Login with Osu!</a>
</body> </body>
</html> </html>

View File

@@ -18,6 +18,10 @@ app.get('/', (req, res) => {
}); });
app.get('/authorize', (req, res) => { app.get('/authorize', (req, res) => {
if(req.query.port != null){
const authorizationUrl = 'https://osu.ppy.sh/oauth/authorize'; const authorizationUrl = 'https://osu.ppy.sh/oauth/authorize';
const redirectUri = `https://${process.env.VERCEL_URL}/callback`; const redirectUri = `https://${process.env.VERCEL_URL}/callback`;
const client_id = process.env.CLIENT_ID; const client_id = process.env.CLIENT_ID;
@@ -25,13 +29,16 @@ app.get('/authorize', (req, res) => {
const scope = 'public identify'; const scope = 'public identify';
const state = 'Randomstate'; const state = 'Randomstate';
res.redirect(`${authorizationUrl}?client_id=${client_id}&redirect_uri=${redirectUri}&response_type=${response_type}&scope=${scope}`); res.redirect(`${authorizationUrl}?client_id=${client_id}&redirect_uri=${redirectUri}&response_type=${response_type}&scope=${scope}&state=${req.query.port}`);
} else {
res.json({ error: "callback port needs to be defined"})
}
}); });
app.get('/callback', async (req, res) => { app.get('/callback', async (req, res) => {
const authorizationCode = req.query.code; const authorizationCode = req.query.code;
console.log(authorizationCode) console.log(req.query.state)
try { try {
const tokenEndpoint = 'https://osu.ppy.sh/oauth/token'; const tokenEndpoint = 'https://osu.ppy.sh/oauth/token';
const requestBody = new URLSearchParams({ const requestBody = new URLSearchParams({