Browse Source

Improved Auth0 integration and fixed locales

Fixes #964
pull/1203/head
Ramiro Saenz 8 years ago
parent
commit
2ce780840b
  1. 8
      app.json
  2. 34
      app/ux/Auth0.js
  3. 10
      app/view/main/MainController.js
  4. 2
      package.json

8
app.json

@ -103,14 +103,6 @@
{ {
"path": "${framework.dir}/build/ext-all-rtl.js" "path": "${framework.dir}/build/ext-all-rtl.js"
}, },
{
"path": "resources/js/auth0-7.1.0.min.js",
"remote": true
},
{
"path": "resources/js/lock-10.2.2/lock.min.js",
"remote": true
},
{ {
"path": "resources/js/GALocalStorage.js" "path": "resources/js/GALocalStorage.js"
}, },

34
app/ux/Auth0.js

@ -9,6 +9,9 @@ Ext.define('Rambox.ux.Auth0', {
,init: function() { ,init: function() {
var me = this; var me = this;
var Auth0Lock = require('auth0-lock').default;
var Auth0 = require('auth0-js');
// Auth0 Config // Auth0 Config
me.lock = new Auth0Lock(auth0Cfg.clientID, auth0Cfg.domain, { me.lock = new Auth0Lock(auth0Cfg.clientID, auth0Cfg.domain, {
autoclose: true autoclose: true
@ -30,7 +33,7 @@ Ext.define('Rambox.ux.Auth0', {
,language: localStorage.getItem('locale-auth0') === null ? 'en' : localStorage.getItem('locale-auth0') ,language: localStorage.getItem('locale-auth0') === null ? 'en' : localStorage.getItem('locale-auth0')
}); });
me.auth0 = new Auth0({ clientID: auth0Cfg.clientID, domain : auth0Cfg.domain }); me.auth0 = new Auth0.WebAuth({ clientID: auth0Cfg.clientID, domain : auth0Cfg.domain });
me.defineEvents(); me.defineEvents();
} }
@ -40,10 +43,15 @@ Ext.define('Rambox.ux.Auth0', {
me.lock.on("authenticated", function(authResult) { me.lock.on("authenticated", function(authResult) {
me.lock.getProfile(authResult.idToken, function(err, profile) { me.lock.getProfile(authResult.idToken, function(err, profile) {
if (err) { if ( err ) {
// Handle error if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration);
Ext.Msg.hide(); Ext.Msg.hide();
return; 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
});
} }
// Display a spinner while waiting // Display a spinner while waiting
@ -141,8 +149,13 @@ Ext.define('Rambox.ux.Auth0', {
me.lock.getProfile(localStorage.getItem('id_token'), function (err, profile) { me.lock.getProfile(localStorage.getItem('id_token'), function (err, profile) {
if ( err ) { if ( err ) {
if ( err.error === 401 ) return me.renewToken(me.restoreConfiguration); if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration);
return alert('There was an error getting the profile: ' + err.message); 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
});
} }
// First we remove all current services // First we remove all current services
@ -163,8 +176,13 @@ Ext.define('Rambox.ux.Auth0', {
me.lock.getProfile(localStorage.getItem('id_token'), function (err, profile) { me.lock.getProfile(localStorage.getItem('id_token'), function (err, profile) {
if ( err ) { if ( err ) {
if ( err.error === 401 ) return me.renewToken(me.checkConfiguration); if ( err.error === 401 || err.error === 'Unauthorized' ) return me.renewToken(me.checkConfiguration);
return alert('There was an error getting the profile: ' + err.message); 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
});
} }
if ( !profile.user_metadata ) { if ( !profile.user_metadata ) {

10
app/view/main/MainController.js

@ -188,8 +188,10 @@ Ext.define('Rambox.view.main.MainController', {
} else { } else {
Ext.cq1('app-main').suspendEvent('remove'); Ext.cq1('app-main').suspendEvent('remove');
Ext.getStore('Services').load(); Ext.getStore('Services').load();
const count = Ext.getStore('Services').getCount();
var i = 1;
Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) { Ext.Array.each(Ext.getStore('Services').collect('id'), function(serviceId) {
me.removeServiceFn(serviceId, 1, 2); me.removeServiceFn(serviceId, count, i++);
}); });
if ( Ext.isFunction(callback) ) callback(); if ( Ext.isFunction(callback) ) callback();
Ext.cq1('app-main').resumeEvent('remove'); Ext.cq1('app-main').resumeEvent('remove');
@ -462,16 +464,12 @@ Ext.define('Rambox.view.main.MainController', {
Ext.cq1('app-main').getViewModel().set('avatar', ''); Ext.cq1('app-main').getViewModel().set('avatar', '');
if ( Ext.isFunction(callback) ) callback(); if ( Ext.isFunction(callback) ) callback();
Ext.Msg.hide();
} }
if ( btn ) { if ( btn ) {
Ext.Msg.confirm(locale['app.main[21]'], locale['app.window[38]'], function(btnId) { Ext.Msg.confirm(locale['app.main[21]'], locale['app.window[38]'], function(btnId) {
if ( btnId === 'yes' ) { if ( btnId === 'yes' ) {
logoutFn(function() { logoutFn(me.removeAllServices.bind(me));
me.removeAllServices();
});
} }
}); });
} else { } else {

2
package.json

@ -101,6 +101,8 @@
}, },
"dependencies": { "dependencies": {
"@exponent/electron-cookies": "2.0.0", "@exponent/electron-cookies": "2.0.0",
"auth0-js": "^8.10.1",
"auth0-lock": "^10.22.0",
"auto-launch-patched": "5.0.2", "auto-launch-patched": "5.0.2",
"electron-config": "0.2.1", "electron-config": "0.2.1",
"electron-is-dev": "^0.1.2", "electron-is-dev": "^0.1.2",

Loading…
Cancel
Save