'Does the response from Notion OAuth contain page id?
In the OAuth process to request authentication from the user(the user is directed to the URL as required by Notion API), there is an authentication code added directly to the redirected URL(/books in the demo below). The access token and some additional information can be exchanged via the authentication code(the API call with post method is made as shown below). But the response contains everything but page id for access(All the returned fields are detailed here). I wonder how can I get the page id which the user authorizes in the authentication picker page.
const express = require("express");
const engine = require("ejs-mate");
const cors = require("cors");
const path = require("path");
const app = express();
const port = 3000;
const { Client } = require("@notionhq/client");
const axios = require("axios");
// Initializing a client
const notion = new Client({
auth: process.env.NOTION_TOKEN,
});
app.engine("ejs", engine);
app.set("views", path.join(__dirname, "/views"));
app.set("view engine", "ejs");
// SERVING STATIC ASSETS
app.use(express.static(path.join(__dirname, "public")));
app.use(cors());
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.get("/books/new", (req, res) => {
res.render("books/new");
});
app.get("/books", async (req, res) => {
const { code } = req.query;
const resp = await axios({
method: "POST",
url: "https://api.notion.com/v1/oauth/token",
auth: { username: notionClientId, password: notionClientSecret },
headers: { "Content-Type": "application/json" },
data: { code, grant_type: "authorization_code" },
});
console.log(resp);
res.send("<script>window.close();</script > ");
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
