Compare commits
73 Commits
Author | SHA1 | Date |
---|---|---|
|
eaa33fc8f3 | 3 years ago |
|
0669dafde5 | 3 years ago |
|
78acfeed42 | 3 years ago |
|
f9e9a547bd | 3 years ago |
|
02aa8ce840 | 3 years ago |
|
6c31dcce1d | 3 years ago |
|
7f3ecf5e1e | 3 years ago |
|
287ee85067 | 3 years ago |
|
b7a5b39b1f | 3 years ago |
|
6fcd982b46 | 3 years ago |
|
5c4ee8d06a | 3 years ago |
|
cb654525e0 | 3 years ago |
|
1eebe2445f | 4 years ago |
|
4a79697487 | 4 years ago |
|
84a8f20bbc | 4 years ago |
|
04413c81eb | 4 years ago |
|
1605ec5ebd | 4 years ago |
|
6f4f33d53d | 4 years ago |
|
f3fc3c7cf0 | 4 years ago |
|
89d0560ed3 | 4 years ago |
|
cc39ed6980 | 4 years ago |
|
58f53323f3 | 4 years ago |
|
82a44e93fc | 4 years ago |
|
c91ef575e3 | 4 years ago |
|
5e94ebf0e9 | 4 years ago |
|
c26845662c | 4 years ago |
|
008efd5f08 | 4 years ago |
|
4f0c6e9bc1 | 4 years ago |
|
e18ff5e003 | 4 years ago |
|
611235aee6 | 5 years ago |
|
a8e5a42e51 | 5 years ago |
|
2037dbafe5 | 5 years ago |
|
5eed7f02fd | 5 years ago |
|
58b5975912 | 5 years ago |
|
f8610047eb | 5 years ago |
|
072997e59c | 5 years ago |
|
4127e0a707 | 5 years ago |
|
e14cfdff86 | 5 years ago |
|
82f70c0c89 | 5 years ago |
|
120512e386 | 5 years ago |
|
dcaa45e86f | 5 years ago |
|
95d04aa76e | 5 years ago |
|
025a8fab68 | 5 years ago |
|
18ae907bd0 | 5 years ago |
|
155a7fd2a2 | 5 years ago |
|
6e1220fbae | 5 years ago |
|
c0293be615 | 5 years ago |
|
03e0c3be2d | 5 years ago |
|
429721393e | 5 years ago |
|
813c0d4628 | 5 years ago |
|
3048d9d28c | 5 years ago |
|
eb88f5d8fc | 5 years ago |
|
d4b89a48ac | 5 years ago |
|
02c0c549ce | 5 years ago |
|
ef2a2a9f15 | 5 years ago |
|
9a5e686bb0 | 5 years ago |
|
01265fdbae | 5 years ago |
|
02c8bacb2a | 5 years ago |
|
c00109417f | 5 years ago |
|
e01453b6a0 | 5 years ago |
|
d748323142 | 5 years ago |
|
7261dd10c6 | 5 years ago |
|
10f577549a | 5 years ago |
|
bec9bae9b9 | 5 years ago |
|
151caa037d | 5 years ago |
|
2185f32dd8 | 5 years ago |
|
168eacb2fe | 5 years ago |
|
9166c49aae | 5 years ago |
|
3326447d0f | 5 years ago |
|
fb1ab0dae5 | 5 years ago |
|
66f16e465d | 5 years ago |
|
7d63ba374e | 5 years ago |
|
e4f6746b28 | 5 years ago |
@ -1,6 +0,0 @@ |
|||||||
# Monthly Donators |
|
||||||
|
|
||||||
[Martin Grünbaum](https://github.com/alathon) |
|
||||||
|
|
||||||
Ivan Toshkov |
|
||||||
[Simon Joda Stößer](https://github.com/SimJoSt) |
|
@ -1,299 +0,0 @@ |
|||||||
Ext.define('Rambox.ux.Auth0', { |
|
||||||
singleton: true |
|
||||||
|
|
||||||
// private
|
|
||||||
,lock: null |
|
||||||
,auth0: null |
|
||||||
,authService: null |
|
||||||
,backupCurrent: false |
|
||||||
|
|
||||||
,init: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
var Auth0 = require('auth0-js'); |
|
||||||
var _AuthService = require('./resources/js/AuthService'); |
|
||||||
|
|
||||||
me.authService = new _AuthService.default({ |
|
||||||
clientId: auth0Cfg.clientID, |
|
||||||
authorizeEndpoint: 'https://'+auth0Cfg.domain+'/authorize', |
|
||||||
audience: 'https://'+auth0Cfg.domain+'/userinfo', |
|
||||||
scope: 'openid profile offline_access', |
|
||||||
redirectUri: 'https://'+auth0Cfg.domain+'/mobile', |
|
||||||
tokenEndpoint: 'https://'+auth0Cfg.domain+'/oauth/token' |
|
||||||
}); |
|
||||||
|
|
||||||
me.auth0 = new Auth0.WebAuth({ clientID: auth0Cfg.clientID, domain : auth0Cfg.domain }); |
|
||||||
|
|
||||||
//me.defineEvents();
|
|
||||||
} |
|
||||||
|
|
||||||
,onLogin: function(token, authWindow) { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
authWindow.close(); |
|
||||||
|
|
||||||
me.auth0.client.userInfo(token.access_token, function(err, profile) { |
|
||||||
if ( err ) { |
|
||||||
if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration); |
|
||||||
Ext.Msg.hide(); |
|
||||||
return Ext.Msg.show({ |
|
||||||
title: 'Error' |
|
||||||
,message: 'There was an error getting the profile: ' + err.error_description |
|
||||||
,icon: Ext.Msg.ERROR |
|
||||||
,buttons: Ext.Msg.OK |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
profile.user_metadata = profile['https://rambox.pro/user_metadata']; |
|
||||||
delete profile['https://rambox.pro/user_metadata']; |
|
||||||
|
|
||||||
// Display a spinner while waiting
|
|
||||||
Ext.Msg.wait(locale['app.window[29]'], locale['app.window[28]']); |
|
||||||
|
|
||||||
// Google Analytics Event
|
|
||||||
ga_storage._trackEvent('Users', 'loggedIn'); |
|
||||||
|
|
||||||
// Set cookies to help Tooltip.io messages segmentation
|
|
||||||
Ext.util.Cookies.set('auth0', true); |
|
||||||
|
|
||||||
// User is logged in
|
|
||||||
// Save the profile and JWT.
|
|
||||||
localStorage.setItem('profile', JSON.stringify(profile)); |
|
||||||
localStorage.setItem('access_token', token.access_token); |
|
||||||
localStorage.setItem('id_token', token.id_token); |
|
||||||
localStorage.setItem('refresh_token', token.refresh_token); |
|
||||||
|
|
||||||
if ( !Ext.isEmpty(profile.user_metadata) && !Ext.isEmpty(profile.user_metadata.services) && !me.backupCurrent ) { |
|
||||||
Ext.each(profile.user_metadata.services, function(s) { |
|
||||||
var service = Ext.create('Rambox.model.Service', s); |
|
||||||
service.save(); |
|
||||||
Ext.getStore('Services').add(service); |
|
||||||
}); |
|
||||||
|
|
||||||
require('electron').remote.getCurrentWindow().reload(); |
|
||||||
} |
|
||||||
|
|
||||||
Ext.Msg.hide(); |
|
||||||
Ext.cq1('app-main').getViewModel().set('username', profile.name); |
|
||||||
Ext.cq1('app-main').getViewModel().set('avatar', profile.picture); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,backupConfiguration: function(callback) { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
Ext.Msg.wait('Saving backup...', 'Please wait...'); |
|
||||||
|
|
||||||
// Getting all services
|
|
||||||
var lastupdate = (new Date()).toJSON(); |
|
||||||
var services = []; |
|
||||||
Ext.getStore('Services').each(function(service) { |
|
||||||
var s = Ext.clone(service); |
|
||||||
delete s.data.id; |
|
||||||
delete s.data.zoomLevel; |
|
||||||
services.push(s.data); |
|
||||||
}); |
|
||||||
|
|
||||||
Ext.Ajax.request({ |
|
||||||
url: 'https://rambox.auth0.com/api/v2/users/'+Ext.decode(localStorage.getItem('profile')).sub |
|
||||||
,method: 'PATCH' |
|
||||||
,headers: { authorization: "Bearer " + localStorage.getItem('id_token') } |
|
||||||
,jsonData: { user_metadata: { services: services, services_lastupdate: lastupdate } } |
|
||||||
,success: function(response) { |
|
||||||
Ext.Msg.hide(); |
|
||||||
// Save the last update in localStorage
|
|
||||||
var profile = Ext.decode(localStorage.getItem('profile')); |
|
||||||
if ( !profile.user_metadata ) profile.user_metadata = {}; |
|
||||||
profile.user_metadata.services_lastupdate = lastupdate; |
|
||||||
localStorage.setItem('profile', Ext.encode(profile)); |
|
||||||
Ext.cq1('app-main').getViewModel().set('last_sync', new Date(lastupdate).toUTCString()); |
|
||||||
|
|
||||||
Ext.toast({ |
|
||||||
html: '<i class="fa fa-check fa-3x fa-pull-left" aria-hidden="true"></i> Your configuration were successfully backed up.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
|
|
||||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
|
||||||
} |
|
||||||
,failure: function(response) { |
|
||||||
if ( response.status === 401 ) return me.renewToken(me.backupConfiguration); |
|
||||||
|
|
||||||
Ext.Msg.hide(); |
|
||||||
Ext.toast({ |
|
||||||
html: '<i class="fa fa-times fa-3x fa-pull-left" aria-hidden="true"></i> Error occurred when trying to backup your configuration.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
|
|
||||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
|
||||||
|
|
||||||
console.error(response); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,restoreConfiguration: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { |
|
||||||
if ( err ) { |
|
||||||
if ( err.code === 401 ) return me.renewToken(me.restoreConfiguration); |
|
||||||
return Ext.Msg.show({ |
|
||||||
title: 'Error' |
|
||||||
,message: 'There was an error getting the profile: ' + err.description |
|
||||||
,icon: Ext.Msg.ERROR |
|
||||||
,buttons: Ext.Msg.OK |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
profile.user_metadata = profile['https://rambox.pro/user_metadata']; |
|
||||||
delete profile['https://rambox.pro/user_metadata']; |
|
||||||
|
|
||||||
// First we remove all current services
|
|
||||||
Ext.cq1('app-main').getController().removeAllServices(false, function() { |
|
||||||
if ( !profile.user_metadata || !profile.user_metadata.services ) return; |
|
||||||
Ext.each(profile.user_metadata.services, function(s) { |
|
||||||
var service = Ext.create('Rambox.model.Service', s); |
|
||||||
service.save(); |
|
||||||
Ext.getStore('Services').add(service); |
|
||||||
}); |
|
||||||
|
|
||||||
require('electron').remote.getCurrentWindow().reload(); |
|
||||||
}); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,checkConfiguration: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
me.auth0.client.userInfo(localStorage.getItem('access_token'), function(err, profile) { |
|
||||||
if ( err ) { |
|
||||||
if ( err.code === 401 ) return me.renewToken(me.checkConfiguration); |
|
||||||
return Ext.Msg.show({ |
|
||||||
title: 'Error' |
|
||||||
,message: 'There was an error getting the profile: ' + err.description |
|
||||||
,icon: Ext.Msg.ERROR |
|
||||||
,buttons: Ext.Msg.OK |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
profile.user_metadata = profile['https://rambox.pro/user_metadata']; |
|
||||||
delete profile['https://rambox.pro/user_metadata']; |
|
||||||
|
|
||||||
if ( !profile.user_metadata ) { |
|
||||||
Ext.toast({ |
|
||||||
html: 'You don\'t have any backup yet.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
if ( Math.floor(new Date(profile.user_metadata.services_lastupdate) / 1000) > Math.floor(new Date(Ext.decode(localStorage.getItem('profile')).user_metadata.services_lastupdate) / 1000) ) { |
|
||||||
Ext.toast({ |
|
||||||
html: 'Your settings are out of date.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
} else { |
|
||||||
Ext.toast({ |
|
||||||
html: '<i class="fa fa-check fa-3x fa-pull-left" aria-hidden="true"></i> Latest backup is already applied.' |
|
||||||
,title: 'Synchronize Configuration' |
|
||||||
,width: 300 |
|
||||||
,align: 't' |
|
||||||
,closable: false |
|
||||||
}); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,renewToken: function(callback) { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
Ext.Ajax.request({ |
|
||||||
url: 'https://rambox.auth0.com/oauth/token' |
|
||||||
,method: 'POST' |
|
||||||
,jsonData: { |
|
||||||
grant_type: 'refresh_token' |
|
||||||
,client_id: auth0Cfg.clientID |
|
||||||
,client_secret: auth0Cfg.clientSecret |
|
||||||
,refresh_token: localStorage.getItem('refresh_token') |
|
||||||
,api_type: 'app' |
|
||||||
} |
|
||||||
,success: function(response) { |
|
||||||
var json = Ext.decode(response.responseText); |
|
||||||
localStorage.setItem('access_token', json.access_token); |
|
||||||
localStorage.setItem('id_token', json.id_token); |
|
||||||
|
|
||||||
if ( Ext.isFunction(callback) ) callback.bind(me)(); |
|
||||||
} |
|
||||||
,failure: function(response) { |
|
||||||
console.error(response); |
|
||||||
} |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,login: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
var electron = require('electron').remote; |
|
||||||
var authWindow = new electron.BrowserWindow({ |
|
||||||
title: 'Rambox - Login' |
|
||||||
,width: 400 |
|
||||||
,height: 600 |
|
||||||
,maximizable: false |
|
||||||
,minimizable: false |
|
||||||
,resizable: false |
|
||||||
,center: true |
|
||||||
,autoHideMenuBar: true |
|
||||||
,skipTaskbar: true |
|
||||||
,fullscreenable: false |
|
||||||
,modal: true |
|
||||||
,parent: require('electron').remote.getCurrentWindow() |
|
||||||
,webPreferences: { |
|
||||||
partition: 'persist:rambox' |
|
||||||
} |
|
||||||
}); |
|
||||||
|
|
||||||
authWindow.on('closed', function() { |
|
||||||
authWindow = null; |
|
||||||
}); |
|
||||||
|
|
||||||
authWindow.loadURL(me.authService.requestAuthCode()); |
|
||||||
|
|
||||||
authWindow.webContents.on('did-start-loading', function(e) { |
|
||||||
authWindow.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => { |
|
||||||
let googleLoginURLs = ['accounts.google.com/signin/oauth', 'accounts.google.com/ServiceLogin'] |
|
||||||
|
|
||||||
googleLoginURLs.forEach((loginURL) => { |
|
||||||
if ( details.url.indexOf(loginURL) > -1 ) details.requestHeaders['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0' }) |
|
||||||
callback({ cancel: false, requestHeaders: details.requestHeaders }); |
|
||||||
}); |
|
||||||
}); |
|
||||||
|
|
||||||
authWindow.webContents.on('did-navigate', function(e, url) { |
|
||||||
me.authService.requestAccessCode(url, me.onLogin.bind(me), authWindow); |
|
||||||
}); |
|
||||||
} |
|
||||||
|
|
||||||
,logout: function() { |
|
||||||
var me = this; |
|
||||||
|
|
||||||
localStorage.removeItem('profile'); |
|
||||||
localStorage.removeItem('id_token'); |
|
||||||
localStorage.removeItem('refresh_token'); |
|
||||||
localStorage.removeItem('access_token'); |
|
||||||
|
|
||||||
// Set cookies to help Tooltip.io messages segmentation
|
|
||||||
Ext.util.Cookies.set('auth0', false); |
|
||||||
} |
|
||||||
}); |
|
@ -1,5 +0,0 @@ |
|||||||
var auth0Cfg = { |
|
||||||
clientID: '' |
|
||||||
,clientSecret: '' |
|
||||||
,domain: '' |
|
||||||
}; |
|
After Width: | Height: | Size: 2.7 KiB |
After Width: | Height: | Size: 62 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 6.9 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 9.7 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 8.6 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 3.4 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 2.4 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 6.3 KiB |
After Width: | Height: | Size: 3.1 KiB |
After Width: | Height: | Size: 4.6 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 4.1 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 6.2 KiB |
After Width: | Height: | Size: 700 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 5.1 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 4.4 KiB |
After Width: | Height: | Size: 4.8 KiB |
After Width: | Height: | Size: 5.5 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 2.5 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 5.6 KiB |
After Width: | Height: | Size: 9.1 KiB |
After Width: | Height: | Size: 4.7 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 3.2 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 6.4 KiB |
After Width: | Height: | Size: 1.8 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 2.8 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 8.5 KiB |
After Width: | Height: | Size: 3.9 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 6.0 KiB |
After Width: | Height: | Size: 2.9 KiB |
After Width: | Height: | Size: 2.8 KiB |