diff --git a/package-lock.json b/package-lock.json index aaeea81..bf74a48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 9eb9da0..014af1e 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/public/index.html b/public/index.html index 402c361..29e050d 100644 --- a/public/index.html +++ b/public/index.html @@ -3,11 +3,10 @@ - OAuth Example + Osu Progress Middleware -

Welcome to My Website

-

Click the following link to authorize with OAuth:

- Authorize th +

Hey u shouldnt be here!

+ Login with Osu! - + \ No newline at end of file diff --git a/server.js b/server.js index 6c58310..436d35d 100644 --- a/server.js +++ b/server.js @@ -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, {