custome scope and callback url

This commit is contained in:
2024-01-10 03:54:48 +01:00
parent fea393077a
commit 77b9243649

View File

@@ -21,13 +21,11 @@ app.get('/authorize', (req, res) => {
if(req.query.port != null){ 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.URL}/callback`; const redirectUri = `https://${process.env.URL}/callback`;
const client_id = process.env.CLIENT_ID; const client_id = process.env.CLIENT_ID;
const response_type = 'code'; const response_type = 'code';
const scope = 'public identify'; const scope = process.env.SCOPE;
const state = 'Randomstate';
res.redirect(`${authorizationUrl}?client_id=${client_id}&redirect_uri=${redirectUri}&response_type=${response_type}&scope=${scope}&state=${req.query.port}`); res.redirect(`${authorizationUrl}?client_id=${client_id}&redirect_uri=${redirectUri}&response_type=${response_type}&scope=${scope}&state=${req.query.port}`);
} else { } else {
@@ -37,8 +35,7 @@ app.get('/authorize', (req, res) => {
app.get('/callback', async (req, res) => { app.get('/callback', async (req, res) => {
const authorizationCode = req.query.code; const authorizationCode = req.query.code;
const callbackport = req.query.state; //port of application
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({
@@ -60,8 +57,7 @@ app.get('/callback', async (req, res) => {
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
console.log(data) console.log(data)
res.redirect(`http://localhost:${req.query.state}/api/callback?access_token=${data.access_token}&refresh_token=${data.refresh_token}&expires_in=${data.expires_in}`) res.redirect(`http://localhost:${callbackport}/${process.env.CALLBACK_URL}?access_token=${data.access_token}&refresh_token=${data.refresh_token}&expires_in=${data.expires_in}`);
//res.json(data);
}) })
.catch(error => console.error('Error:', error)); .catch(error => console.error('Error:', error));