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", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^1.6.5", "axios": "^1.6.5",
"dotenv": "^16.3.1",
"express": "^4.18.2" "express": "^4.18.2"
} }
}, },
@@ -178,6 +179,17 @@
"npm": "1.2.8000 || >= 1.4.16" "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": { "node_modules/ee-first": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "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", "description": "small server to see how login button works",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"axios": "^1.6.5", "axios": "^1.6.5",
"dotenv": "^16.3.1",
"express": "^4.18.2" "express": "^4.18.2"
} }
} }

View File

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

View File

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