From 83c34b3a590ef5b413ae89a66fbb971ea002c204 Mon Sep 17 00:00:00 2001 From: winsdominoes Date: Mon, 8 Jul 2024 18:04:50 +0700 Subject: [PATCH] check authentication status --- config/config.json | 1 - package-lock.json | 16 +++++++++++++++- package.json | 3 ++- src/index.js | 43 +++++++++++++++++++++++++++++++++++++++---- 4 files changed, 56 insertions(+), 7 deletions(-) diff --git a/config/config.json b/config/config.json index e3a3cf9..688727e 100644 --- a/config/config.json +++ b/config/config.json @@ -2,7 +2,6 @@ "host": "https://misskey.winscloud.net", "app": { "name": "bkkraindarbot", - "icon": "", "callback": "http://localhost:4000/callback", "permission": "write:notes,write:following,read:drive" } diff --git a/package-lock.json b/package-lock.json index 88c9b3d..65591de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "ISC", "dependencies": { "express": "^4.19.2", - "misskey-js": "^2024.5.0" + "misskey-js": "^2024.5.0", + "uuid": "^10.0.0" } }, "node_modules/accepts": { @@ -771,6 +772,19 @@ "node": ">= 0.4.0" } }, + "node_modules/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "license": "MIT", + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vary": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", diff --git a/package.json b/package.json index 5d8b5d3..a694d2e 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "license": "ISC", "dependencies": { "express": "^4.19.2", - "misskey-js": "^2024.5.0" + "misskey-js": "^2024.5.0", + "uuid": "^10.0.0" } } diff --git a/src/index.js b/src/index.js index e1366c2..ee095c7 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,50 @@ +const uuid = require("uuid"); +const fs = require("fs"); +const path = require("path"); + const express = require("express"); -var app = express(); -var port = process.env.PORT || 4000; +let app = express(); +let port = process.env.PORT || 4000; const config = JSON.parse(fs.readFileSync(path.resolve("config", "config.json"))); let host = config.host; +let app_name = config.app.name; +let app_callback = config.app.callback; +let app_permission = config.app.permission; + // https://misskey.io/miauth/c1f6d42b-468b-4fd2-8274-e58abdedef6f?name=MyApp&callback=https%3A%2F%2Fmyapp.example.com%2Fcallback&permission=write:notes,write:following,read:drive +let session_id = uuid.v4(); +let auth_url = `${host}/miauth/${session_id}?name=${app_name}&callback=${app_callback}&permission=${app_permission}`; +let auth_status = 0; + +console.log(auth_url); + app.get('/callback', function(req, res) { - + res.send({ + "status": 200, + "success": true, + }) + + auth_status = 1; }); +async function check_auth_status() { + setInterval(() => { + console.log("Checking auth status..."); + + if(auth_status == 1) { + console.log("Bot has been authenticated"); + clearInterval(check_auth_status); + return true; + } + }, 2000); +}; + +async function get_access_token() { + +} + app.listen(port); -console.log('Callback URL: http://localhost:4000/callback' + port); \ No newline at end of file +console.log(`Callback URL: http://localhost:${port}/callback`); \ No newline at end of file