Skip to content

Commit 22427fa

Browse files
committed
trying to get the right code for oauth, also might need to figure out if gzip needs to be factored in
1 parent 3c9f022 commit 22427fa

File tree

8 files changed

+148
-100
lines changed

8 files changed

+148
-100
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#secret Api keys, Webhook URLs etc
2+
slackApiStuff.js
3+
.env
4+
#
15
.quasar
26
.DS_Store
37
.thumbs.db

package-lock.json

Lines changed: 22 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"aws-amplify-vue": "^0.2.13",
2727
"aws-appsync": "^1.8.1",
2828
"dot-prop": "^6.0.0",
29+
"dotenv": "^10.0.0",
2930
"electron-deeplink": "^1.0.8",
3031
"fs-extra": "^8.1.0",
3132
"localforage": "^1.7.3",

quasar.conf.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// https://quasar.dev/quasar-cli/quasar-conf-js
33

44
module.exports = function (ctx) {
5+
console.log('webpack\'s context parameter: ', ctx)
56
return {
67
// app boot file (/src/boot)
78
// --> boot files are part of "main.js"
@@ -99,8 +100,8 @@ module.exports = function (ctx) {
99100
},
100101

101102
devServer: {
102-
https: true,
103-
port: 8080,
103+
// https: true,
104+
// port: 8080,
104105
open: true // opens browser window automatically
105106
},
106107

src-electron/main-process/electron-main.js

Lines changed: 112 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { app, BrowserWindow, net, shell, ipcMain } from "electron";
22
import { Deeplink } from "electron-deeplink";
33
import isDev from "electron-is-dev";
44

5-
import slackApiStuff from '../../secretStuff/slackApiStuff'
5+
import slackApiStuff from "../../secretStuff/slackApiStuff";
66

7-
const clientId = slackApiStuff.clientId
8-
const clientSecret = slackApiStuff.clientSecret
7+
const clientId = slackApiStuff.clientId;
8+
const clientSecret = slackApiStuff.clientSecret;
9+
import dotenv from "dotenv";
10+
dotenv.config();
911

1012
/**
1113
* Set `__statics` path to static files in production;
@@ -20,103 +22,127 @@ if (process.env.PROD) {
2022
let mainWindow;
2123
let authCode;
2224

23-
function logEverywhere(...toBeLogged) {
24-
console.log(...toBeLogged);
25-
if (mainWindow && mainWindow.webContents) {
26-
mainWindow.webContents.executeJavaScript(`console.log("${toBeLogged}")`);
25+
function logEverywhere(toBeLogged) {
26+
if (isDev) {
27+
console.log(toBeLogged);
28+
} else {
29+
console.log(toBeLogged);
30+
if (mainWindow && mainWindow.webContents) {
31+
mainWindow.webContents.executeJavaScript(
32+
'console.log("' + toBeLogged + '" )'
33+
);
34+
}
2735
}
2836
}
2937

30-
const protocol = isDev ? 'overvuedev' : 'overvue'
38+
const protocol = isDev ? "overvuedev" : "overvue";
3139
const deeplink = new Deeplink({
3240
app,
3341
mainWindow,
3442
protocol,
35-
isDev ,
43+
isDev,
3644
debugLogging: true,
37-
electronPath: '../../node_modules/electron/dist/electron.exe'
45+
electronPath: "../../node_modules/electron/dist/electron.exe"
3846
});
3947
// ipcMain.handle('slackAuth', slackAuth)
4048

41-
let deeplinkingUrl;
42-
43-
function customDeepLink() {
44-
if (isDev && process.platform === 'win32') {
45-
// Set the path of electron.exe and your app.
46-
// These two additional parameters are only available on windows.
47-
// Setting this is required to get this working in dev mode.
48-
app.setAsDefaultProtocolClient('overvuedev', process.execPath, [
49-
resolve(process.argv[1])
50-
]);
51-
} else {
52-
app.setAsDefaultProtocolClient('overvue');
53-
}
54-
55-
app.on('open-url', function (event, url) {
56-
event.preventDefault();
57-
deeplinkingUrl = url;
58-
});
59-
60-
// Force single application instance
61-
const gotTheLock = app.requestSingleInstanceLock();
62-
63-
if (!gotTheLock) {
64-
app.quit();
65-
return;
66-
} else {
67-
app.on('second-instance', (e, argv) => {
68-
if (process.platform !== 'darwin') {
69-
// Find the arg that is our custom protocol url and store it
70-
deeplinkingUrl = argv.find((arg) => arg.startsWith('overvuedev://test'));
71-
}
72-
73-
if (myWindow) {
74-
if (myWindow.isMinimized()) myWindow.restore();
75-
myWindow.focus();
76-
}
77-
})
78-
}
79-
}
80-
49+
// function customDeepLink() {
50+
// let deeplinkingUrl;
51+
52+
// if (isDev && process.platform === 'win32') {
53+
// // Set the path of electron.exe and your app.
54+
// // These two additional parameters are only available on windows.
55+
// // Setting this is required to get this working in dev mode.
56+
// app.setAsDefaultProtocolClient('overvuedev', process.execPath, [
57+
// resolve(process.argv[1])
58+
// ]);
59+
// } else {
60+
// app.setAsDefaultProtocolClient('overvue');
61+
// }
62+
63+
// app.on('open-url', function (event, url) {
64+
// event.preventDefault();
65+
// deeplinkingUrl = url;
66+
// });
67+
68+
// // Force single application instance
69+
// const gotTheLock = app.requestSingleInstanceLock();
70+
71+
// if (!gotTheLock) {
72+
// app.quit();
73+
// return;
74+
// } else {
75+
// app.on('second-instance', (e, argv) => {
76+
// if (process.platform !== 'darwin') {
77+
// // Find the arg that is our custom protocol url and store it
78+
// deeplinkingUrl = argv.find((arg) => arg.startsWith('overvuedev://test'));
79+
// }
80+
81+
// if (myWindow) {
82+
// if (myWindow.isMinimized()) myWindow.restore();
83+
// myWindow.focus();
84+
// }
85+
// })
86+
// }
87+
// }
88+
89+
function getSlackAuth() {
90+
logEverywhere("inside getSlackAuth");
8191

82-
function getSlackAuth () {
8392
const authData = {
8493
client_id: clientId,
8594
client_secret: clientSecret,
8695
code: authCode,
87-
redirect_uri: isDev ? 'overvuedev://test' : 'overvue://slack'
88-
}
89-
96+
redirect_uri: isDev ? "overvuedev://test" : "overvue://slack"
97+
};
98+
logEverywhere(authData.code)
99+
// https://slack.com/api/openid.connect.token?client_id=2696943977700.2696948669268&client_secret=6a6206cc93da2e49243ee9683f958438&code=2696943977700.2713919388452.23b787dec24adec68eeca105f6b7d6e517425de1033a1b6bc5ba3e116b933619&redirect_uri=overvue://slack
100+
const url =
101+
"https://slack.com/api/openid.connect.token?" +
102+
"client_id=" +
103+
authData.client_id +
104+
"&client_secret=" +
105+
authData.client_secret +
106+
"&code=" +
107+
authData.code +
108+
"&redirect_uri=" +
109+
authData.redirect_uri;
110+
logEverywhere(url);
90111
const request = net.request({
91-
method: 'POST',
92-
url: 'https://slack.com/api/openid.connect.token?' +
93-
'client_id=' + authData.client_id +
94-
'&client_secret=' + authData.client_secret +
95-
'&code=' + authData.authCode +
96-
'&redirect_uri=' + authData.redirect_uri,
112+
method: "POST",
113+
url: url,
97114
headers: {
98-
'Content-Type': 'application/x-www-form-urlencoded',
115+
"Content-Type": "application/x-www-form-urlencoded"
99116
// 'Content-Length': authData.length
100117
}
101-
})
102-
103-
request.on('response', (response) => {
104-
logEverywhere('RESPONSE RECEIVED SON')
105-
JSON.parse(response)
106-
.then(data => {
107-
logEverywhere('response with token: ')
108-
logEverywhere(response)
109-
mainWindow.webContents.send('tokenReceived', response)
110-
})
111-
})
112-
request.end()
118+
});
119+
120+
request.on("response", response => {
121+
let body;
122+
logEverywhere("RESPONSE RECEIVED SON");
123+
mainWindow.webContents.send("tokenReceived", response);
124+
// logEverywhere('STATUS: ', response.statusCode)
125+
// logEverywhere(`HEADERS: ${JSON.stringify(response.headers)}`)
126+
response.on("data", data => {
127+
// logEverywhere(`response.on datas CHUNK: ${chunk}`)
128+
logEverywhere("chunked");
129+
logEverywhere(data);
130+
body = data;
131+
});
132+
response.on("end", () => {
133+
logEverywhere("Response ended ");
134+
mainWindow.webContents.send("tokenReceived", body);
135+
});
136+
});
137+
request.end();
113138
}
114139

115-
function getSlackToken () {
140+
function getSlackToken() {
116141
return deeplink.on("received", link => {
117-
logEverywhere('auth worked here link: ', link)
118-
authCode = link.split('=')[1]
119-
getSlackAuth()
142+
logEverywhere(`auth worked here link: ${link}`);
143+
authCode = link.split("=")[1];
144+
// authCode = link.split("=")[1].split(".")[2];
145+
getSlackAuth();
120146
});
121147
}
122148

@@ -135,18 +161,18 @@ function createWindow() {
135161
}
136162
});
137163

138-
logEverywhere('current protocol ', deeplink.getProtocol())
139-
mainWindow.loadURL(process.env.APP_URL)
164+
logEverywhere(`current protocol ${deeplink.getProtocol()}`);
165+
mainWindow.loadURL(process.env.APP_URL);
140166

141167
mainWindow.on("closed", () => {
142168
mainWindow = null;
143169
});
144170
}
145171

146172
app.on("ready", () => {
147-
createWindow()
148-
getSlackToken()
149-
logEverywhere("process.env: ", process.env)
173+
createWindow();
174+
getSlackToken();
175+
logEverywhere(`process.env.CLIENT_ID: ${process.env.CLIENT_ID}`);
150176
});
151177

152178
app.on("window-all-closed", () => {
@@ -157,8 +183,8 @@ app.on("window-all-closed", () => {
157183

158184
app.on("activate", () => {
159185
if (mainWindow === null) {
160-
createWindow()
161-
getSlackToken()
162-
logEverywhere("process.env: ", process.env)
186+
createWindow();
187+
getSlackToken();
188+
logEverywhere(`process.env: ${process.env}`);
163189
}
164-
})
190+
});

src/components/slack_login/SlackLoginWindow.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
}
3737
},
3838
created () {
39-
ipcRenderer.once('tokenReceived', (data) => {
39+
ipcRenderer.on('tokenReceived', (data) => {
4040
console.log('data received in SlackLoginWindow: ', data)
4141
})
4242
},

src/layouts/MyLayout.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import ExportProjectComponent from '../components/file_system_interface/ExportPr
4949
import SaveProjectComponent from '../components/file_system_interface/SaveProjectComponent.vue'
5050
import OpenProjectComponent from '../components/file_system_interface/OpenProjectComponent.vue'
5151
import UploadImage from '../components/home_sidebar_items/UploadImage.vue'
52+
import SlackLoginWindow from '../components/slack_login/SlackLoginWindow.vue'
5253
5354
export default {
5455
data () {
@@ -64,7 +65,8 @@ export default {
6465
ExportProjectComponent,
6566
SaveProjectComponent,
6667
OpenProjectComponent,
67-
UploadImage
68+
UploadImage,
69+
SlackLoginWindow
6870
},
6971
methods: {
7072
undo () {

src/router/routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
const routes = [
33
{
4-
path: '/',
4+
path: '/start',
55
// redirect: ''
66
component: () => import('components/slack_login/SlackLoginWindow.vue')
77
},
@@ -11,7 +11,7 @@ const routes = [
1111
redirect: '/pow'
1212
},
1313
{
14-
path: '/sdfg',
14+
path: '/',
1515
component: () => import('layouts/MyLayout.vue'),
1616
children: [
1717
{ path: '', component: () => import('pages/Index.vue') }

0 commit comments

Comments
 (0)