-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathlogin-or-register-oidc.js
82 lines (67 loc) · 2.41 KB
/
login-or-register-oidc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { SessionStorageEntry } from '../../utils/session-storage-entry';
const oidcUserAuthenticationStorage = new SessionStorageEntry('oidcUserAuthentication');
export default class LoginOrRegisterOidcController extends Controller {
queryParams = ['identityProviderSlug'];
@service url;
@service oidcIdentityProviders;
@service store;
@service intl;
@service locale;
@service router;
@service currentDomain;
@tracked showOidcReconciliation = false;
@tracked identityProviderSlug = null;
@tracked email = '';
@tracked fullNameFromPix = '';
@tracked fullNameFromExternalIdentityProvider = '';
@tracked username = '';
@tracked authenticationMethods = [];
get showcase() {
return this.url.showcase;
}
get oidcUserAuthenticationStorage() {
return oidcUserAuthenticationStorage.get();
}
get userClaims() {
return this.oidcUserAuthenticationStorage?.userClaims;
}
get isInternationalDomain() {
return !this.currentDomain.isFranceDomain;
}
get selectedLanguage() {
return this.intl.primaryLocale;
}
get authenticationKey() {
return this.oidcUserAuthenticationStorage?.authenticationKey;
}
@action
onLanguageChange(language) {
this.locale.setLocale(language);
this.router.replaceWith('authentication.login-or-register-oidc', { queryParams: { lang: null } });
}
@action toggleOidcReconciliation() {
this.showOidcReconciliation = !this.showOidcReconciliation;
}
@action
async onLogin({ enteredEmail, enteredPassword }) {
const identityProvider = this.oidcIdentityProviders[this.identityProviderSlug].code;
const authenticationRequest = this.store.createRecord('user-oidc-authentication-request', {
password: enteredPassword,
email: enteredEmail,
authenticationKey: this.authenticationKey,
identityProvider,
});
const { email, username, authenticationMethods, fullNameFromPix, fullNameFromExternalIdentityProvider } =
await authenticationRequest.login();
this.email = email;
this.username = username;
this.authenticationMethods = authenticationMethods;
this.fullNameFromPix = fullNameFromPix;
this.fullNameFromExternalIdentityProvider = fullNameFromExternalIdentityProvider;
this.toggleOidcReconciliation();
}
}