mirror of
https://github.com/documize/community.git
synced 2025-08-04 13:05:23 +02:00
keycloak logout and auth provider switching
This commit is contained in:
parent
8c062d592a
commit
0f9d673eb5
12 changed files with 78 additions and 45 deletions
|
@ -23,6 +23,7 @@ const {
|
|||
export default Base.extend({
|
||||
ajax: service(),
|
||||
appMeta: service(),
|
||||
localStorage: service(),
|
||||
|
||||
restore(data) {
|
||||
// TODO: verify authentication data
|
||||
|
@ -57,6 +58,7 @@ export default Base.extend({
|
|||
},
|
||||
|
||||
invalidate() {
|
||||
this.get('localStorage').clearAll();
|
||||
return resolve();
|
||||
}
|
||||
});
|
|
@ -22,6 +22,8 @@ const {
|
|||
export default Base.extend({
|
||||
ajax: service(),
|
||||
appMeta: service(),
|
||||
kcAuth: service(),
|
||||
localStorage: service(),
|
||||
|
||||
restore(data) {
|
||||
// TODO: verify authentication data
|
||||
|
@ -46,6 +48,7 @@ export default Base.extend({
|
|||
},
|
||||
|
||||
invalidate() {
|
||||
return resolve();
|
||||
this.get('localStorage').clearAll();
|
||||
return this.get('kcAuth').logout();
|
||||
}
|
||||
});
|
|
@ -18,9 +18,9 @@ const {
|
|||
} = Ember;
|
||||
|
||||
export default Ember.Component.extend({
|
||||
appMeta: Ember.inject.service(),
|
||||
isDocumizeProvider: computed.equal('authProvider', constants.AuthProvider.Documize),
|
||||
isKeycloakProvider: computed.equal('authProvider', constants.AuthProvider.Keycloak),
|
||||
|
||||
KeycloakUrlError: computed.empty('keycloakConfig.url'),
|
||||
KeycloakRealmError: computed.empty('keycloakConfig.realm'),
|
||||
KeycloakClientIdError: computed.empty('keycloakConfig.clientId'),
|
||||
|
|
|
@ -25,11 +25,7 @@ export default Ember.Route.extend({
|
|||
|
||||
beforeModel(transition) {
|
||||
this.set('mode', is.not.undefined(transition.queryParams.mode) ? transition.queryParams.mode : 'login');
|
||||
|
||||
let authProvider = this.get('appMeta.authProvider');
|
||||
let authConfig = this.get('appMeta.authConfig');
|
||||
|
||||
if (authProvider !== constants.AuthProvider.Keycloak) {
|
||||
if (this.get('appMeta.authProvider') !== constants.AuthProvider.Keycloak) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -37,12 +33,12 @@ export default Ember.Route.extend({
|
|||
return;
|
||||
}
|
||||
|
||||
this.get('kcAuth').boot(JSON.parse(authConfig)).then((kc) => {
|
||||
this.get('kcAuth').boot().then((kc) => {
|
||||
if (!kc.authenticated) {
|
||||
this.get('kcAuth').login().then(() => {
|
||||
}, (reject) => {
|
||||
this.get('localStorage').storeSessionItem('kc-error', reject);
|
||||
this.transitionTo('auth.keycloak', { queryParams: { mode: 'reject' }});
|
||||
this.set('mode', 'reject');
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -53,16 +49,16 @@ export default Ember.Route.extend({
|
|||
this.transitionTo('folders');
|
||||
}, (reject) => {
|
||||
this.get('localStorage').storeSessionItem('kc-error', reject);
|
||||
this.transitionTo('auth.keycloak', { queryParams: { mode: 'reject' }});
|
||||
this.set('mode', 'reject');
|
||||
});
|
||||
|
||||
}, (reject) => {
|
||||
this.get('localStorage').storeSessionItem('kc-error', reject);
|
||||
this.transitionTo('auth.keycloak', { queryParams: { mode: 'reject' }});
|
||||
this.set('mode', 'reject');
|
||||
});
|
||||
}, (reject) => {
|
||||
this.get('localStorage').storeSessionItem('kc-error', reject);
|
||||
this.transitionTo('auth.keycloak', { queryParams: { mode: 'reject' }});
|
||||
this.set('mode', 'reject');
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -20,13 +20,12 @@ export default Ember.Route.extend({
|
|||
|
||||
beforeModel(/*transition*/) {
|
||||
let authProvider = this.get('appMeta.authProvider');
|
||||
let authConfig = this.get('appMeta.authConfig');
|
||||
|
||||
switch (authProvider) {
|
||||
case constants.AuthProvider.Keycloak:
|
||||
this.set('showLogin', false);
|
||||
|
||||
this.get('kcAuth').boot(JSON.parse(authConfig)).then(() => {
|
||||
this.get('kcAuth').boot().then(() => {
|
||||
this.get('kcAuth').login().then(() => {
|
||||
}, (reject) => {
|
||||
this.get('localStorage').storeSessionItem('kc-error', reject);
|
||||
|
|
|
@ -17,18 +17,19 @@ export default Ember.Route.extend({
|
|||
appMeta: Ember.inject.service(),
|
||||
|
||||
activate: function () {
|
||||
this.get('session').invalidate();
|
||||
this.audit.record("logged-in");
|
||||
this.audit.record("logged-out");
|
||||
this.audit.stop();
|
||||
|
||||
if (config.environment === 'test') {
|
||||
this.transitionTo('auth.login');
|
||||
} else {
|
||||
if (this.get("appMeta.allowAnonymousAccess")) {
|
||||
this.transitionTo('folders');
|
||||
} else {
|
||||
this.get('session').invalidate().then(() => {
|
||||
if (config.environment === 'test') {
|
||||
this.transitionTo('auth.login');
|
||||
} else {
|
||||
if (this.get("appMeta.allowAnonymousAccess")) {
|
||||
this.transitionTo('folders');
|
||||
} else {
|
||||
this.transitionTo('auth.login');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1 +1,4 @@
|
|||
{{outlet}}
|
||||
<div class="sso-box">
|
||||
<p>Logging out...</p>
|
||||
<img src="/assets/img/busy-gray.gif" />
|
||||
</div>
|
||||
|
|
|
@ -15,6 +15,7 @@ import NotifierMixin from "../../../mixins/notifier";
|
|||
export default Ember.Controller.extend(NotifierMixin, {
|
||||
global: Ember.inject.service(),
|
||||
appMeta: Ember.inject.service(),
|
||||
session: Ember.inject.service(),
|
||||
|
||||
actions: {
|
||||
onSave(provider, config) {
|
||||
|
@ -23,8 +24,15 @@ export default Ember.Controller.extend(NotifierMixin, {
|
|||
|
||||
return this.get('global').saveAuthConfig(data).then(() => {
|
||||
this.showNotification('Saved');
|
||||
this.set('appMeta.authProvider', provider);
|
||||
this.set('appMeta.authConfig', config);
|
||||
if (provider !== this.get('appMeta.authProvider')) {
|
||||
this.get('session').logout();
|
||||
this.set('appMeta.authProvider', provider);
|
||||
this.set('appMeta.authConfig', config);
|
||||
window.location.href= '/';
|
||||
} else {
|
||||
this.set('appMeta.authProvider', provider);
|
||||
this.set('appMeta.authConfig', config);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
|
|
@ -23,11 +23,16 @@ export default Ember.Service.extend({
|
|||
appMeta: service(),
|
||||
keycloak: null,
|
||||
|
||||
boot(options) {
|
||||
this.set('keycloak', new Keycloak(options));
|
||||
init () {
|
||||
this._super(...arguments);
|
||||
this.keycloak = null;
|
||||
},
|
||||
|
||||
boot() {
|
||||
this.set('keycloak', new Keycloak(JSON.parse(this.get('appMeta.authConfig'))));
|
||||
|
||||
return new Ember.RSVP.Promise((resolve, reject) => {
|
||||
this.keycloak.init().success(() => {
|
||||
this.get('keycloak').init().success(() => {
|
||||
this.get('audit').record("initialized-keycloak");
|
||||
resolve(this.get('keycloak'));
|
||||
}).error((err) => {
|
||||
|
@ -37,15 +42,35 @@ export default Ember.Service.extend({
|
|||
},
|
||||
|
||||
login() {
|
||||
this.set('keycloak', new Keycloak(JSON.parse(this.get('appMeta.authConfig'))));
|
||||
let url = netUtil.getAppUrl(netUtil.getSubdomain()) + '/auth/keycloak?mode=login';
|
||||
|
||||
return new Ember.RSVP.Promise((resolve, reject) => {
|
||||
if (this.get('keycloak').authenticated) {
|
||||
return resolve(this.get('keycloak'));
|
||||
}
|
||||
this.boot().then(() => {
|
||||
this.get('keycloak').login({redirectUri: url}).success(() => {
|
||||
return resolve();
|
||||
}).error(() => {
|
||||
return reject(new Error('login failed'));
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
this.get('keycloak').login( {redirectUri: url} );
|
||||
return reject();
|
||||
logout() {
|
||||
this.set('keycloak', new Keycloak(JSON.parse(this.get('appMeta.authConfig'))));
|
||||
|
||||
return new Ember.RSVP.Promise((resolve, reject) => {
|
||||
this.boot().then(() => {
|
||||
this.get('keycloak').logout(JSON.parse(this.get('appMeta.authConfig'))).success(() => {
|
||||
this.get('keycloak').clearToken();
|
||||
resolve();
|
||||
}).error((error) => {
|
||||
this.get('keycloak').clearToken();
|
||||
reject(error);
|
||||
});
|
||||
}, (error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ export default SimpleAuthSession.extend({
|
|||
ajax: service(),
|
||||
appMeta: service(),
|
||||
store: service(),
|
||||
|
||||
localStorage: service(),
|
||||
folderPermissions: null,
|
||||
currentFolder: null,
|
||||
isMac: false,
|
||||
isMobile: false,
|
||||
authenticated: computed('user.id', function () {
|
||||
|
@ -55,6 +57,7 @@ export default SimpleAuthSession.extend({
|
|||
}
|
||||
}),
|
||||
|
||||
folderPermissions: null,
|
||||
currentFolder: null
|
||||
logout() {
|
||||
this.get('localStorage').clearAll();
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue