@@ -39,8 +39,10 @@ const deeplink = new Deeplink({
39
39
debugLogging : true
40
40
} ) ;
41
41
42
- function getSlackAuth ( ) {
43
- logEverywhere ( "inside getSlackAuth" ) ;
42
+ // Sends request to Slack for User's information,
43
+ // then sends user information back to renderer process
44
+ function sendTokenRequest ( ) {
45
+ logEverywhere ( "inside sendTokenRequest" ) ;
44
46
45
47
const authData = {
46
48
client_id : process . env . SLACK_CLIENT_ID ,
@@ -49,6 +51,7 @@ function getSlackAuth() {
49
51
redirect_uri : isDev ? "overvuedev://test" : "overvue://slack"
50
52
} ;
51
53
logEverywhere ( authData . code ) ;
54
+
52
55
const url =
53
56
"https://slack.com/api/openid.connect.token?" +
54
57
"client_id=" +
@@ -60,41 +63,49 @@ function getSlackAuth() {
60
63
"&grant_type=authorization_code" +
61
64
"&redirect_uri=" +
62
65
authData . redirect_uri ;
63
- logEverywhere ( url ) ;
66
+
67
+ logEverywhere ( `Token Request URL: ${ url } ` ) ;
68
+
69
+ // Send Post request for user information
64
70
const request = net . request ( {
65
71
method : "POST" ,
66
72
url : url ,
67
73
headers : {
68
74
"Content-Type" : "application/x-www-form-urlencoded"
69
- // 'Content-Length': authData.length
70
75
}
71
76
} ) ;
72
77
78
+ // Listens for response from token request
73
79
request . on ( "response" , response => {
74
80
// logEverywhere("request.on response received");
75
81
response . on ( "end" , ( ) => {
76
82
logEverywhere ( "Response ended " ) ;
77
83
} ) ;
78
84
response . on ( "data" , data => {
79
- logEverywhere ( "res on data " ) ;
85
+ // logEverywhere("response.on data ");
86
+ // decodes utf8 Buffer into JSON, then parses it
80
87
const decoded = JSON . parse ( data . toString ( ) )
88
+
89
+ // decodes JSON Web Token and places decoded JWT back into response data
81
90
decoded . id_token = jwt_decode ( decoded . id_token )
82
- // logEverywhere(data + ')'); //error
83
- logEverywhere ( `decoded in response.on data: ${ decoded } ` )
84
- logEverywhere ( 'SEND #2' )
91
+ // logEverywhere(`decoded in response.on data: ${decoded}`)
92
+ // send user information back to renderer process
85
93
mainWindow . webContents . send ( "tokenReceived" , decoded ) ;
86
94
} ) ;
87
95
} ) ;
88
96
request . end ( ) ;
89
97
}
90
98
91
- function getSlackToken ( ) {
99
+ // Turns on event listener for Slack Oauth deep linking back app
100
+ // TODO: Deep linking currently doesn't work properly in dev mode - requires fix
101
+ function setOauthListener ( ) {
92
102
logEverywhere ( `process.env.SLACK_CLIENT_ID in electron-main: ${ process . env . SLACK_CLIENT_ID } ` ) ;
93
103
logEverywhere ( `process.env.SLACK_CLIENT_SECRET in electron-main: ${ process . env . SLACK_CLIENT_SECRET } ` ) ;
94
104
return deeplink . on ( "received" , link => {
95
- // logEverywhere(`auth worked here link: ${link}`);
105
+ logEverywhere ( `auth worked here link: ${ link } ` ) ;
106
+ // Extracts Slack authorization code from deep link
96
107
authCode = link . split ( "=" ) [ 1 ] ;
97
- getSlackAuth ( ) ;
108
+ sendTokenRequest ( ) ;
98
109
} ) ;
99
110
}
100
111
@@ -123,7 +134,7 @@ function createWindow() {
123
134
124
135
app . on ( "ready" , ( ) => {
125
136
createWindow ( ) ;
126
- getSlackToken ( ) ;
137
+ setOauthListener ( ) ;
127
138
} ) ;
128
139
129
140
app . on ( "window-all-closed" , ( ) => {
@@ -135,6 +146,6 @@ app.on("window-all-closed", () => {
135
146
app . on ( "activate" , ( ) => {
136
147
if ( mainWindow === null ) {
137
148
createWindow ( ) ;
138
- getSlackToken ( ) ;
149
+ setOauthListener ( ) ;
139
150
}
140
151
} ) ;
0 commit comments