check authentication status

This commit is contained in:
Win 2024-07-08 18:04:50 +07:00
parent 8b7bc50772
commit 83c34b3a59
4 changed files with 56 additions and 7 deletions

View File

@ -2,7 +2,6 @@
"host": "https://misskey.winscloud.net", "host": "https://misskey.winscloud.net",
"app": { "app": {
"name": "bkkraindarbot", "name": "bkkraindarbot",
"icon": "",
"callback": "http://localhost:4000/callback", "callback": "http://localhost:4000/callback",
"permission": "write:notes,write:following,read:drive" "permission": "write:notes,write:following,read:drive"
} }

16
package-lock.json generated
View File

@ -10,7 +10,8 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"express": "^4.19.2", "express": "^4.19.2",
"misskey-js": "^2024.5.0" "misskey-js": "^2024.5.0",
"uuid": "^10.0.0"
} }
}, },
"node_modules/accepts": { "node_modules/accepts": {
@ -771,6 +772,19 @@
"node": ">= 0.4.0" "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": { "node_modules/vary": {
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",

View File

@ -12,6 +12,7 @@
"license": "ISC", "license": "ISC",
"dependencies": { "dependencies": {
"express": "^4.19.2", "express": "^4.19.2",
"misskey-js": "^2024.5.0" "misskey-js": "^2024.5.0",
"uuid": "^10.0.0"
} }
} }

View File

@ -1,15 +1,50 @@
const uuid = require("uuid");
const fs = require("fs");
const path = require("path");
const express = require("express"); const express = require("express");
var app = express(); let app = express();
var port = process.env.PORT || 4000; let port = process.env.PORT || 4000;
const config = JSON.parse(fs.readFileSync(path.resolve("config", "config.json"))); const config = JSON.parse(fs.readFileSync(path.resolve("config", "config.json")));
let host = config.host; 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 // 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
app.get('/callback', function(req, res) { 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); app.listen(port);
console.log('Callback URL: http://localhost:4000/callback' + port); console.log(`Callback URL: http://localhost:${port}/callback`);