Skip to content

Commit 24539dd

Browse files
author
jg
committed
Merge branch 'development'
2 parents b6a12ba + d4ab2b2 commit 24539dd

File tree

3 files changed

+131
-6
lines changed

3 files changed

+131
-6
lines changed

gui/index.html

+30-4
Original file line numberDiff line numberDiff line change
@@ -279,17 +279,43 @@ <h1>Firebot</h1>
279279
<div class="streamer col-6">
280280
<div class="avatar"><img src="./images/placeholders/default.jpg" class="streamer-avatar"></div>
281281
<div class="username">
282-
<h2>Streamer</h2></div>
283-
<div class="loginOrOut">
282+
<h2>Streamer</h2>
283+
</div>
284+
<div class="loginOrOut beam-login">
284285
<button class="streamer-login btn" data="streamer" status="login">Login</button>
286+
<div class="alt-login-link"><a href="#">Login with Microsoft, Twitter, or Discord.</a></div>
287+
</div>
288+
<div class="alternative-login" style="display:none">
289+
<div class="auth-code">
290+
<label class="col-form-label">Auth Code</label>
291+
<input class="form-control" type="password" placeholder="Auth Code" data-toggle="tooltip" data-placement="left" title="Paste in auth code.">
292+
</div>
293+
<div class="login-buttons">
294+
<button class="get-auth-code btn">Get Code</button>
295+
<button class="streamer-alt-login btn" data="streamer" status="login">Login</button>
296+
<div class="beam-login-link"><a href="#">Login with Beam.</a></div>
297+
</div>
285298
</div>
286299
</div>
287300
<div class="bot col-6">
288301
<div class="avatar"><img src="./images/placeholders/default.jpg" class="bot-avatar"></div>
289302
<div class="username">
290-
<h2>Bot</h2></div>
291-
<div class="loginOrOut">
303+
<h2>Bot</h2>
304+
</div>
305+
<div class="loginOrOut beam-login">
292306
<button class="bot-login btn" data="bot" status="login">Login</button>
307+
<div class="alt-login-link"><a href="#">Login with Microsoft, Twitter, or Discord.</a></div>
308+
</div>
309+
<div class="alternative-login" style="display:none">
310+
<div class="auth-code">
311+
<label class="col-form-label">Auth Code</label>
312+
<input class="form-control" type="password" placeholder="Auth Code" data-toggle="tooltip" data-placement="left" title="Paste in auth code.">
313+
</div>
314+
<div class="login-buttons">
315+
<button class="get-auth-code btn">Get Code</button>
316+
<button class="bot-alt-login btn" data="bot" status="login">Login</button>
317+
<div class="beam-login-link"><a href="#">Login with Beam.</a></div>
318+
</div>
293319
</div>
294320
</div>
295321
</div>

gui/js/login.js

+98-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const JsonDB = require('node-json-db');
22
const request = require('request');
3-
const {ipcRenderer} = require('electron')
3+
const {ipcRenderer} = require('electron');
4+
const shell = require('electron').shell;
45

56
// JSON DBs
67
var dbAuth = new JsonDB("./user-settings/auth", true, false);
@@ -100,6 +101,57 @@ function initialLogin(){
100101
}
101102
}
102103

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+
103155
// Login or out button pressed
104156
// This checks if button is logging in or out a person or bot. If logging in then it sends message to main process.
105157
$( ".streamer-login, .bot-login" ).click(function() {
@@ -113,6 +165,51 @@ $( ".streamer-login, .bot-login" ).click(function() {
113165
}
114166
});
115167

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+
});
116213

117214
// Run on App Load
118215
initialLogin();

lib/login/login.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const JsonDB = require('node-json-db');
66
// This works in conjunction with the render login.js file and acts when a login button has been pressed.
77
// It grabs the auth token and then sends it back to the render process login.js.
88
ipcMain.on('oauth-login', function(event, streamOrBot) {
9+
10+
// If these options are changed they also need to be adjusted in the gui login.js for alternative logins.
911
var options = {
1012
client_id: 'f78304ba46861ddc7a8c1fb3706e997c3945ef275d7618a9',
1113
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.
@@ -31,7 +33,7 @@ ipcMain.on('oauth-login', function(event, streamOrBot) {
3133
}, false);
3234

3335
var url = "https://beam.pro/oauth/authorize?";
34-
var authUrl = url + "client_id=" + options.client_id + "&scope=" + options.scopes.join(' ') + "&redirect_uri=http://localhost/callback" + "&response_type=token";
36+
var authUrl = url + "client_id=" + options.client_id + "&scope=" + options.scopes.join(' ') + "&redirect_uri=http://firebottle.tv/Firebot/oauth" + "&response_type=token";
3537
authWindow.loadURL(encodeURI(authUrl));
3638
authWindow.show();
3739

0 commit comments

Comments
 (0)