Skip to content

Commit 9930878

Browse files
fix: πŸ› OIDC authentications not properly showing username
βœ… Closes: https://hashicorp.atlassian.net/browse/ICU-17231
1 parent 4cd56f8 commit 9930878

File tree

4 files changed

+39
-9
lines changed

4 files changed

+39
-9
lines changed

β€Žaddons/auth/addon/authenticators/base.jsβ€Ž

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import SimpleAuthBaseAuthenticator from 'ember-simple-auth/authenticators/base';
77
import { resolve, reject } from 'rsvp';
88
import { waitForPromise } from '@ember/test-waiters';
9+
import { service } from '@ember/service';
910

1011
/**
1112
* Encapsulates common authenticator functionality.
@@ -19,6 +20,10 @@ import { waitForPromise } from '@ember/test-waiters';
1920
* All other responses should resolve the session restoration successfully.
2021
*/
2122
export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator {
23+
// =services
24+
25+
@service store;
26+
2227
// =unimplemented methods
2328

2429
/**
@@ -101,15 +106,41 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator {
101106
* @param {string} username
102107
* @return {object}
103108
*/
104-
normalizeData(data, username) {
109+
async normalizeData(data) {
105110
// Pull fields up from `data.attributes` for easier access in JavaScript.
106111
// The `attributes` field exists on the Go side for its convenience but is
107112
// unnecessary here.
108113
Object.assign(data, data.attributes);
109114
// Add booleans indicated the scope type
110115
data.isGlobal = data?.scope?.type === 'global';
111116
data.isOrg = data?.scope?.type === 'org';
112-
if (username) data.username = username;
117+
118+
try {
119+
const adapter = this.store.adapterFor('application');
120+
const findAccountRecordURL = adapter.buildURL(
121+
'account',
122+
data?.account_id,
123+
{},
124+
'findRecord',
125+
);
126+
const response = await waitForPromise(
127+
fetch(findAccountRecordURL, {
128+
method: 'get',
129+
headers: { Authorization: `Bearer ${data.attributes.token}` },
130+
}),
131+
);
132+
133+
const authenticatedAccount = await response.json();
134+
135+
if (response.status === 200) {
136+
const { email, full_name, login_name, subject } =
137+
authenticatedAccount.attributes;
138+
data.username = email || full_name || login_name || subject;
139+
}
140+
} catch (_) {
141+
/* no op */
142+
}
143+
113144
return data;
114145
}
115146

β€Žaddons/auth/addon/authenticators/password.jsβ€Ž

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ export default class PasswordAuthenticator extends BaseAuthenticator {
7272
fetch(authEndpointURL, { method: 'post', body }),
7373
);
7474
const json = await response.json();
75-
return response.status < 400
76-
? resolve(this.normalizeData(json, login_name))
77-
: reject();
75+
return response.status < 400 ? resolve(this.normalizeData(json)) : reject();
7876
}
7977
}

β€Žaddons/core/translations/en-us.yamlβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ titles:
4949
project-actions: Project Actions
5050
user-menu: User Menu
5151
back-link: 'Back to {scope}'
52+
authenticated: Signed In
5253
descriptions:
5354
empty-set: There are no items to display yet. You may be able to add items or try back later.
5455
cluster-url-initialization: To get started, please enter your cluster URL

β€Žui/admin/app/templates/application.hbsβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@
6363
data-test-side-nav-user-dropdown
6464
as |dd|
6565
>
66+
<dd.ToggleIcon @icon='user' @text={{t 'titles.user-menu'}} />
6667
{{#if this.session.data.authenticated.username}}
67-
<dd.ToggleButton
68-
@icon='user'
68+
<dd.Title @text={{t 'titles.authenticated'}} />
69+
<dd.Description
6970
@text={{this.session.data.authenticated.username}}
7071
/>
71-
{{else}}
72-
<dd.ToggleIcon @icon='user' @text={{t 'titles.user-menu'}} />
72+
<dd.Separator />
7373
{{/if}}
7474

7575
<dd.Interactive @route='account.change-password'>{{t

0 commit comments

Comments
Β (0)