diff --git a/index.js b/index.js new file mode 100644 index 0000000..ab0c967 --- /dev/null +++ b/index.js @@ -0,0 +1,76 @@ +const Express = require('express') +const app = Express() +const port = 3000 + +const axios = require('axios') +require('dotenv').config() + +const hbs = require('hbs') + +hbs.registerPartials(__dirname + '/views/partials') +app.set('view engine', 'hbs') + +app.use(Express.static('public')); + +app.get('/auth', async (req, res) => { + + console.log(req.query) + console.log(process.env.NOTION_INTEGRATION_ID) + console.log(process.env.NOTION_INTEGRATION_SECRET) + + async function requestAccessToken() { + try { + const reqData = { + code: req.query.code, + grant_type: "authorization_code", + redirect_uri: "https://telegram-to-notion.herokuapp.com/auth" + } + + const auth = { + Authorization: "Basic " + Buffer.from(`${process.env.NOTION_INTEGRATION_ID}:${process.env.NOTION_INTEGRATION_SECRET}`).toString('base64') + } + + console.log(auth) + + const response = await axios({ + method: "POST", + url: "https://api.notion.com/v1/oauth/token", + data: reqData, + auth: { + username: Buffer.from(process.env.NOTION_INTEGRATION_ID.toString('base64')), + password: Buffer.from(process.env.NOTION_INTEGRATION_SECRET.toString('base64')) + } //THANK YOU https://stackoverflow.com/questions/67534080/notion-api-invalid-client-oauth-integration/68699544#68699544?newreg=949504cf865c4a52b2c0ce7afe936c9b + }) + + console.log(response.status) //400 in positive case + console.log(response.data) + + /** + * access_token: string, + * token_type: string, + * bot_id: string, + * workspace_name: string, + * workspace_icon: string, + * workspace_id: string + */ + + return response + } + catch (error) { + console.log("error") + console.log(error) + + return {status: 400} + } + } + + const response = await requestAccessToken() + + res.render('auth', { + name: "fran", + success: response.status === 200 ? true : false, + data: response.data + }) +}) + +app.listen(port, () => console.log('port', port)) \ No newline at end of file diff --git a/package.json b/package.json index a8cd265..247ea4a 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,10 @@ "name": "telegram-to-notion-website", "version": "1.0.0", "description": "Website for the Telegram to Notion Bot", - "main": "src/index.js", + "main": "index.js", "scripts": { - "dev": "nodemon src/index.js" + "dev": "nodemon index.js", + "start": "node index.js" }, "keywords": [ "telegram", @@ -18,6 +19,9 @@ "nodemon": "^2.0.15" }, "dependencies": { - "express": "^4.17.3" + "axios": "^0.26.1", + "dotenv": "^16.0.0", + "express": "^4.17.3", + "hbs": "^4.2.0" } } diff --git a/public/css/auth.css b/public/css/auth.css new file mode 100644 index 0000000..8ec7a58 --- /dev/null +++ b/public/css/auth.css @@ -0,0 +1,25 @@ +.request-success { + + display: flex; + align-items: center; + + background-color: #ffebcd; + + padding: 3vh 0px 3vh 2vw; + + user-select: all; + -webkit-user-select: all; +} + +.request-success img { + + width: 50px; + + margin-right: 3vw; + + user-select: none; +} + +.request-error { + color: rgb(143, 0, 0) +} \ No newline at end of file diff --git a/public/css/global.css b/public/css/global.css new file mode 100644 index 0000000..27fa96d --- /dev/null +++ b/public/css/global.css @@ -0,0 +1,9 @@ +html, body { + margin: 0; + padding: 0; +} + +body { + margin: 0vh 3vw; + font-family: 'Be Vietnam Pro', sans-serif; +} \ No newline at end of file diff --git a/public/img/auth_copy.svg b/public/img/auth_copy.svg new file mode 100644 index 0000000..2eb127c --- /dev/null +++ b/public/img/auth_copy.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/index.js b/src/index.js deleted file mode 100644 index e69de29..0000000 diff --git a/views/auth.hbs b/views/auth.hbs new file mode 100644 index 0000000..ec4decc --- /dev/null +++ b/views/auth.hbs @@ -0,0 +1,18 @@ +{{> global cssFile="auth"}} + + +
+ {{#if success}} +

Copy the following code on the Telegram chat

+
+ copy + {{data.access_token}} +
+ {{else}} +
+

There has been an error authorizing the app, please try again

+
+ {{/if}} +
+ + \ No newline at end of file diff --git a/views/partials/global.hbs b/views/partials/global.hbs new file mode 100644 index 0000000..2ab0e53 --- /dev/null +++ b/views/partials/global.hbs @@ -0,0 +1,13 @@ + + + + + + + + + + Telegram to Notion + + + \ No newline at end of file