mirror of
https://github.com/documize/community.git
synced 2025-08-04 21:15:24 +02:00
keycloak jwt processing
This commit is contained in:
parent
a585a55033
commit
b5f85637a7
9 changed files with 334 additions and 121 deletions
|
@ -11,7 +11,6 @@
|
|||
|
||||
import Ember from 'ember';
|
||||
import Base from 'ember-simple-auth/authenticators/base';
|
||||
import encodingUtil from '../utils/encoding';
|
||||
import netUtil from '../utils/net';
|
||||
|
||||
const {
|
||||
|
@ -33,27 +32,17 @@ export default Base.extend({
|
|||
return reject();
|
||||
},
|
||||
|
||||
authenticate(credentials) {
|
||||
let domain = netUtil.getSubdomain();
|
||||
let encoded;
|
||||
authenticate(data) {
|
||||
data.domain = netUtil.getSubdomain();
|
||||
|
||||
if (typeof credentials === 'object') {
|
||||
let { password, email } = credentials;
|
||||
|
||||
if (!isPresent(password) || !isPresent(email)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
}
|
||||
|
||||
encoded = encodingUtil.Base64.encode(`${domain}:${email}:${password}`);
|
||||
} else if (typeof credentials === 'string') {
|
||||
encoded = credentials;
|
||||
} else {
|
||||
if (!isPresent(data.token) || !isPresent(data.email)) {
|
||||
return Ember.RSVP.reject("invalid");
|
||||
}
|
||||
|
||||
let headers = { 'Authorization': 'Basic ' + encoded };
|
||||
|
||||
return this.get('ajax').post('public/authenticate', { headers });
|
||||
return this.get('ajax').post('public/authenticate/keycloak', {
|
||||
data: JSON.stringify(data),
|
||||
contentType: 'json'
|
||||
});
|
||||
},
|
||||
|
||||
invalidate() {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
import Ember from 'ember';
|
||||
import constants from '../utils/constants';
|
||||
import encoding from '../utils/encoding';
|
||||
|
||||
const {
|
||||
computed
|
||||
|
@ -46,6 +47,7 @@ export default Ember.Component.extend({
|
|||
config = {};
|
||||
} else {
|
||||
config = JSON.parse(config);
|
||||
config.publicKey = encoding.Base64.decode(config.publicKey);
|
||||
}
|
||||
|
||||
this.set('keycloakConfig', config);
|
||||
|
@ -98,7 +100,8 @@ export default Ember.Component.extend({
|
|||
|
||||
this.set('keycloakConfig.publicKey', pk);
|
||||
|
||||
config = this.get('keycloakConfig');
|
||||
config = Ember.copy(this.get('keycloakConfig'));
|
||||
Ember.set(config, 'publicKey', encoding.Base64.encode(pk));
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,17 +44,19 @@ export default Ember.Route.extend({
|
|||
this.get('kcAuth').fetchProfile(kc).then((profile) => {
|
||||
let data = this.get('kcAuth').mapProfile(kc, profile);
|
||||
|
||||
console.log(kc);
|
||||
console.log(profile);
|
||||
console.log(data);
|
||||
// console.log(kc);
|
||||
// console.log(profile);
|
||||
// console.log(data);
|
||||
|
||||
// this.get("session").authenticate('authenticator:keycloak', data)
|
||||
// .then(() => {
|
||||
// this.transitionTo('folders');
|
||||
// }, () => {
|
||||
// this.transitionTo('auth.login');
|
||||
// console.log(">>>>> Documize SSO failure");
|
||||
// });
|
||||
this.get("session").authenticate('authenticator:keycloak', data).then(() => {
|
||||
debugger;
|
||||
this.get('audit').record("logged-in-keycloak");
|
||||
this.transitionTo('folders');
|
||||
}, (reject) => {
|
||||
debugger;
|
||||
console.log(">>>>> Documize Keycloak authentication failure");
|
||||
this.transitionTo('auth.login');
|
||||
});
|
||||
|
||||
}, (err) => {
|
||||
console.log(err);
|
||||
|
|
|
@ -43,29 +43,6 @@ export default Ember.Controller.extend({
|
|||
}).catch(() => {
|
||||
this.set('invalidCredentials', true);
|
||||
});
|
||||
|
||||
// let authProvider = this.get('appMeta.authProvider');
|
||||
// let authConfig = this.get('appMeta.authConfig');
|
||||
// switch (authProvider) {
|
||||
// case constants.AuthProvider.Documize:
|
||||
// let creds = this.getProperties('email', 'password');
|
||||
|
||||
// this.get('session').authenticate('authenticator:documize', creds)
|
||||
// .then((response) => {
|
||||
// this.get('audit').record("logged-in");
|
||||
// this.transitionToRoute('folders');
|
||||
// return response;
|
||||
// }).catch(() => {
|
||||
// this.set('invalidCredentials', true);
|
||||
// });
|
||||
|
||||
// break;
|
||||
|
||||
// case constants.AuthProvider.Keycloak:
|
||||
// // this.get('session').authenticate('authenticator:keycloak', authConfig);
|
||||
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -63,13 +63,14 @@ export default Ember.Service.extend({
|
|||
|
||||
mapProfile(kc, profile) {
|
||||
return {
|
||||
domain: '',
|
||||
token: kc.token,
|
||||
enabled: profile.enabled,
|
||||
email: profile.email,
|
||||
username: profile.username,
|
||||
firstname: profile.firstName,
|
||||
lastname: profile.lastName,
|
||||
remoteId: profile.id
|
||||
remoteId: is.null(profile.id) || is.undefined(profile.id) ? profile.email: profile.id,
|
||||
email: is.null(profile.email) || is.undefined(profile.email) ? '': profile.email,
|
||||
username: is.null(profile.username) || is.undefined(profile.username) ? '': profile.username,
|
||||
firstname: is.null(profile.firstName) || is.undefined(profile.firstName) ? profile.username: profile.firstName,
|
||||
lastname: is.null(profile.lastName) || is.undefined(profile.lastName) ? profile.username: profile.lastName,
|
||||
enabled: is.null(profile.enabled) || is.undefined(profile.enabled) ? true: profile.enabled
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue