1
1
const JsonDB = require ( 'node-json-db' ) ;
2
2
const request = require ( 'request' ) ;
3
- const { ipcRenderer} = require ( 'electron' )
3
+ const { ipcRenderer} = require ( 'electron' ) ;
4
+ const shell = require ( 'electron' ) . shell ;
4
5
5
6
// JSON DBs
6
7
var dbAuth = new JsonDB ( "./user-settings/auth" , true , false ) ;
@@ -100,6 +101,57 @@ function initialLogin(){
100
101
}
101
102
}
102
103
104
+ // Alternative Login External Page
105
+ // This opens up the external auth page for people with alternative logins.
106
+ function altLoginUrl ( ) {
107
+
108
+ // If these options are changed they also need to be adjusted in the lib login.js for the main login process.
109
+ var options = {
110
+ client_id : 'f78304ba46861ddc7a8c1fb3706e997c3945ef275d7618a9' ,
111
+ scopes : [ "user:details:self" , "interactive:manage:self" , "interactive:robot:self" , "chat:connect" , "chat:bypass_slowchat" , "chat:bypass_links" , "chat:chat" , "chat:whisper" ] // Scopes limit access for OAuth tokens.
112
+ } ;
113
+
114
+ // Piece together URL and send them to auth page. Then redirect to firebottle.tv to copy/paste their token.
115
+ var url = "https://beam.pro/oauth/authorize?" ;
116
+ var authUrl = url + "client_id=" + options . client_id + "&scope=" + options . scopes . join ( ' ' ) + "&redirect_uri=http://firebottle.tv/Firebot/oauth" + "&response_type=token" ;
117
+
118
+ shell . openExternal ( encodeURI ( authUrl ) ) ;
119
+ }
120
+
121
+
122
+ // Alternative Login Finished
123
+ // This take the auth code in the field and kicks off the login process.
124
+ function altLoginFinish ( streamOrBot ) {
125
+ if ( streamOrBot == "streamer" ) {
126
+ var token = $ ( '.streamer .auth-code input' ) . val ( ) ;
127
+
128
+ // Switch back to regular clean login.
129
+ $ ( '.streamer .alternative-login' ) . fadeOut ( 'fast' , function ( ) {
130
+ $ ( '.streamer .beam-login' ) . fadeIn ( 'fast' ) ;
131
+ } )
132
+
133
+ // Start up login process
134
+ requestBeamData ( token , streamOrBot )
135
+
136
+ // Clear token field.
137
+ $ ( '.streamer .auth-code input' ) . val ( '' ) ;
138
+ } else {
139
+ var token = $ ( '.bot .auth-code input' ) . val ( ) ;
140
+
141
+ // Switch back to regular clean login.
142
+ $ ( '.bot .alternative-login' ) . fadeOut ( 'fast' , function ( ) {
143
+ $ ( '.bot .beam-login' ) . fadeIn ( 'fast' ) ;
144
+ } )
145
+
146
+ // Start up login process
147
+ requestBeamData ( token , streamOrBot )
148
+
149
+ // Clear token field.
150
+ $ ( '.bot .auth-code input' ) . val ( '' ) ;
151
+ }
152
+ }
153
+
154
+
103
155
// Login or out button pressed
104
156
// This checks if button is logging in or out a person or bot. If logging in then it sends message to main process.
105
157
$ ( ".streamer-login, .bot-login" ) . click ( function ( ) {
@@ -113,6 +165,51 @@ $( ".streamer-login, .bot-login" ).click(function() {
113
165
}
114
166
} ) ;
115
167
168
+ // Alternative Login Link
169
+ // This checks if the alternative login link has been clicked.
170
+ // It will open up the auth page on click and swap out the fields on the login page to prepare.
171
+ $ ( ".streamer .alt-login-link a" ) . click ( function ( ) {
172
+ $ ( '.streamer .beam-login' ) . fadeOut ( 'fast' , function ( ) {
173
+ $ ( '.streamer .alternative-login' ) . fadeIn ( 'fast' ) ;
174
+ } )
175
+ } ) ;
176
+ $ ( ".bot .alt-login-link a" ) . click ( function ( ) {
177
+ $ ( '.bot .beam-login' ) . fadeOut ( 'fast' , function ( ) {
178
+ $ ( '.bot .alternative-login' ) . fadeIn ( 'fast' ) ;
179
+ } )
180
+ } ) ;
181
+
182
+ // Beam Login Link
183
+ // This checks if the beam login link has been clicked.
184
+ // This just switches back to the regular login buttons.
185
+ $ ( ".streamer .beam-login-link a" ) . click ( function ( ) {
186
+ $ ( '.streamer .alternative-login' ) . fadeOut ( 'fast' , function ( ) {
187
+ $ ( '.streamer .beam-login' ) . fadeIn ( 'fast' ) ;
188
+ } )
189
+ } ) ;
190
+ $ ( ".bot .beam-login-link a" ) . click ( function ( ) {
191
+ $ ( '.bot .alternative-login' ) . fadeOut ( 'fast' , function ( ) {
192
+ $ ( '.bot .beam-login' ) . fadeIn ( 'fast' ) ;
193
+ } )
194
+ } ) ;
195
+
196
+ // Beam Alternative Login Button
197
+ // This checks if the beam login link has been clicked.
198
+ // This just switches back to the regular login buttons.
199
+ $ ( ".streamer-alt-login" ) . click ( function ( ) {
200
+ var streamOrBot = $ ( this ) . attr ( 'data' ) ;
201
+ altLoginFinish ( streamOrBot )
202
+ } ) ;
203
+ $ ( ".bot-alt-login" ) . click ( function ( ) {
204
+ var streamOrBot = $ ( this ) . attr ( 'data' ) ;
205
+ altLoginFinish ( streamOrBot )
206
+ } ) ;
207
+
208
+ // Get Alternative Auth Code
209
+ // This checks if the get code button was clicked, and if so it opens up the external url to start that process.
210
+ $ ( ".get-auth-code" ) . click ( function ( ) {
211
+ altLoginUrl ( ) ;
212
+ } ) ;
116
213
117
214
// Run on App Load
118
215
initialLogin ( ) ;
0 commit comments