Integrate full instagram oauth
This commit is contained in:
26
app.js
26
app.js
@@ -1,14 +1,34 @@
|
||||
import { data } from "./wwwroot/core/appData.js";
|
||||
import express from "express";
|
||||
import {Logger} from "./wwwroot/core/logging/logger.js";
|
||||
import {launch} from "./bot.js";
|
||||
|
||||
//await launch();
|
||||
console.log(data.instagramTokenManager.getOauthUrl());
|
||||
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
|
||||
app.get("/oauth/", async (req, res) => {
|
||||
const code = req.query.code;
|
||||
console.log("Received OAuth code:", code);
|
||||
await data.instagramTokenManager.generate(code);
|
||||
|
||||
let resMsg = "";
|
||||
try{
|
||||
const shortLived = await data.instagramTokenManager.generateShortLivedToken(code);
|
||||
const longLived = await data.instagramTokenManager.generateLongLivedToken(shortLived);
|
||||
console.log(longLived);
|
||||
resMsg = "Authentication successful. You can close this tab";
|
||||
} catch(err){
|
||||
console.log(err);
|
||||
await Logger.error(`Unable to generate token from code ${code}`, err);
|
||||
resMsg = "An error occurred. Try again in few minutes.";
|
||||
} finally {
|
||||
res.send(`
|
||||
<html lang="en">
|
||||
<head><title>Authentication</title></head>
|
||||
<body>${resMsg}</body>
|
||||
</html>
|
||||
`);
|
||||
}
|
||||
});
|
||||
|
||||
app.get("/api/health", (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user