diff --git a/index.js b/index.js new file mode 100644 index 0000000..a02e4f6 --- /dev/null +++ b/index.js @@ -0,0 +1,87 @@ +const Express = require('express') +const app = Express() +const port = (process.env.PORT || 3030) + +const axios = require('axios') +require('dotenv').config() + +const favicon = require('serve-favicon'); +app.use(favicon(__dirname + '/public/favicon.ico')); + +const hbs = require('hbs') + +hbs.registerPartials(__dirname + '/views/partials') +app.set('view engine', 'hbs') + +app.use(Express.static('public')); + +app.get('/', (req, res) => { + res.render('index') +}) + +app.get('/auth', async (req, res) => { + + 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.get('/privacy-policy', (req, res) => { + res.render('privacy-policy') +}) + +app.get('/terms-of-use', (req, res) => { + res.render('terms-of-use') +}) + +app.listen(port, () => console.log('port', port)) \ No newline at end of file diff --git a/public/css/auth.css b/public/css/auth.css new file mode 100644 index 0000000..f5a785c --- /dev/null +++ b/public/css/auth.css @@ -0,0 +1,29 @@ +.request-success { + + display: flex; + align-items: center; + + background-color: #ffebcd; + + padding: 3vh 0px 3vh 2vw; + + user-select: all; + -webkit-user-select: all; +} + +.request-success code { + overflow-wrap: anywhere; +} + +.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..c20e0a9 --- /dev/null +++ b/public/css/global.css @@ -0,0 +1,21 @@ +html, body { + margin: 0; + padding: 0; +} + +body { + margin: 0vh 3vw; + font-family: 'Be Vietnam Pro', sans-serif; +} + +#beta-banner { + background-color: #F38181; + color: #393E46; + + padding: 2vh 0.5vw; + margin: 0px -3vw; +} + +#beta-banner p { + margin: 0; +} \ No newline at end of file diff --git a/public/css/index.css b/public/css/index.css new file mode 100644 index 0000000..2a346e1 --- /dev/null +++ b/public/css/index.css @@ -0,0 +1,26 @@ +.main { + display: flex; + flex-direction: column; +} + +.button { + width: fit-content; + + background-color: #4797ff; + color: #fff; + + padding: 2vh 5vw; + + border-radius: 5px; + + text-decoration: none; + font-weight: bold; +} + +ul { + margin-top: 5vh; +} +ul li{ + font-size: 20pt; + font-weight: bold; +} \ No newline at end of file diff --git a/public/favicon.png b/public/favicon.png new file mode 100644 index 0000000..e4e0bf7 Binary files /dev/null and b/public/favicon.png differ 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/README.md b/readme.MD similarity index 100% rename from README.md rename to readme.MD diff --git a/src/Pages/Auth.jsx b/src/Pages/Auth.jsx new file mode 100644 index 0000000..f2a71a1 --- /dev/null +++ b/src/Pages/Auth.jsx @@ -0,0 +1,79 @@ +import React, {useState} from "react" +import axios from 'axios' + +function Auth() { + + const [loading, setLoading] = useState(true) + const [permanentCode, setPermanentCode] = useState(false) + + const getPermanentCode = () => { + + const temporalCode = new URLSearchParams(window.location.search).get("code") + console.log(temporalCode); + + if (!temporalCode) { + console.log("No temporal code") + return + } + + let requestUrl + + if (process.env.REACT_APP_ENV_MODE === "production") { + requestUrl = "https://telegram-to-notion-backend.herokuapp.com/api/v1/auth" + } else { + requestUrl = "http://localhost:5050/api/v1/auth" + } + + axios({ + method: "POST", + url: requestUrl, + headers: {'Content-Type': 'application/json'}, + data: {code: temporalCode} + }) + .then(res => { + console.log(res) + setPermanentCode(res ? res.data : null) + }) + .catch(err => { + console.log(err.response) + setPermanentCode(false) + }) + .finally(() => { + setLoading(false) + }) + } + React.useEffect(() => { + getPermanentCode() + }, []) + + + return ( +
+ // {permanentCode}
+ //
+ // {{data.access_token}}
+