mirror of
https://github.com/FranP-code/Open-Telegram-to-Notion-Backend.git
synced 2025-10-12 23:52:54 +00:00
Authorization page done
This commit is contained in:
76
index.js
Normal file
76
index.js
Normal file
@@ -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))
|
||||||
10
package.json
10
package.json
@@ -2,9 +2,10 @@
|
|||||||
"name": "telegram-to-notion-website",
|
"name": "telegram-to-notion-website",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Website for the Telegram to Notion Bot",
|
"description": "Website for the Telegram to Notion Bot",
|
||||||
"main": "src/index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nodemon src/index.js"
|
"dev": "nodemon index.js",
|
||||||
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"telegram",
|
"telegram",
|
||||||
@@ -18,6 +19,9 @@
|
|||||||
"nodemon": "^2.0.15"
|
"nodemon": "^2.0.15"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"express": "^4.17.3"
|
"axios": "^0.26.1",
|
||||||
|
"dotenv": "^16.0.0",
|
||||||
|
"express": "^4.17.3",
|
||||||
|
"hbs": "^4.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
25
public/css/auth.css
Normal file
25
public/css/auth.css
Normal file
@@ -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)
|
||||||
|
}
|
||||||
9
public/css/global.css
Normal file
9
public/css/global.css
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
html, body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0vh 3vw;
|
||||||
|
font-family: 'Be Vietnam Pro', sans-serif;
|
||||||
|
}
|
||||||
1
public/img/auth_copy.svg
Normal file
1
public/img/auth_copy.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24" fill="none" stroke="#b6a894" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
|
||||||
|
After Width: | Height: | Size: 348 B |
18
views/auth.hbs
Normal file
18
views/auth.hbs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
{{> global cssFile="auth"}}
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div>
|
||||||
|
{{#if success}}
|
||||||
|
<h2>Copy the following code on the Telegram chat</h2>
|
||||||
|
<div class="request-success">
|
||||||
|
<img src="/img/auth_copy.svg" alt="copy">
|
||||||
|
<code>{{data.access_token}}</code>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="request-error">
|
||||||
|
<h2>There has been an error authorizing the app, please try again</h2>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
13
views/partials/global.hbs
Normal file
13
views/partials/global.hbs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:wght@400;700;900&display=swap" rel="stylesheet">
|
||||||
|
<title>Telegram to Notion</title>
|
||||||
|
<link rel="stylesheet" href="/css/global.css">
|
||||||
|
<link rel="stylesheet" href="/css/{{cssFile}}.css">
|
||||||
|
</head>
|
||||||
Reference in New Issue
Block a user