This commit is contained in:
2024-01-10 01:35:30 +01:00
parent dcb8031597
commit 6c7cfe5242
4 changed files with 25 additions and 12 deletions

12
package-lock.json generated
View File

@@ -10,6 +10,7 @@
"license": "ISC",
"dependencies": {
"axios": "^1.6.5",
"dotenv": "^16.3.1",
"express": "^4.18.2"
}
},
@@ -178,6 +179,17 @@
"npm": "1.2.8000 || >= 1.4.16"
}
},
"node_modules/dotenv": {
"version": "16.3.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz",
"integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/motdotla/dotenv?sponsor=1"
}
},
"node_modules/ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",

View File

@@ -4,12 +4,14 @@
"description": "small server to see how login button works",
"main": "index.js",
"scripts": {
"build": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^1.6.5",
"dotenv": "^16.3.1",
"express": "^4.18.2"
}
}

View File

@@ -3,11 +3,10 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>OAuth Example</title>
<title>Osu Progress Middleware</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>Click the following link to authorize with OAuth:</p>
<a href='/authorize' target="_blank">Authorize th</a>
<p>Hey u shouldnt be here!</p>
<a href='/authorize' target="_blank">Login with Osu!</a>
</body>
</html>

View File

@@ -1,8 +1,8 @@
const express = require('express');
const axios = require('axios')
require('dotenv').config();
const app = express();
const port = 4000;
const port = process.env.PORT || 9000;
let tokenData;
@@ -19,8 +19,8 @@ app.get('/', (req, res) => {
app.get('/authorize', (req, res) => {
const authorizationUrl = 'https://osu.ppy.sh/oauth/authorize';
const redirectUri = 'http://localhost:4000/callback';
const client_id = process.argv[2];
const redirectUri = `http://localhost:${port}/callback`;
const client_id = process.env.CLIENT_ID;
const response_type = 'code';
const scope = 'public identify';
const state = 'Randomstate';
@@ -35,11 +35,11 @@ app.get('/callback', async (req, res) => {
try {
const tokenEndpoint = 'https://osu.ppy.sh/oauth/token';
const requestBody = new URLSearchParams({
'client_id': process.argv[2],
'client_secret': process.argv[3],
'client_id': process.env.CLIENT_ID,
'client_secret': process.env.CLIENT_SECRET,
'code': authorizationCode,
'grant_type': 'authorization_code',
'redirect_uri': 'http://localhost:4000/callback'
'redirect_uri': `http://localhost:${port}/callback`
});
fetch(tokenEndpoint, {