fix: 🐛 OIDC authentications not properly showing username (#2930)
* fix: 🐛 properly show username for oidc auth method in user menu * test: 💍 fix admin ui tests * test: 💍 fix desktop ui tests * refactor: 💡 admin to not store username in authenticated object * refactor: 💡 use getter in app controller * test: 💍 POC for how we could update our tests to use auth account * refactor: 💡 remove unused service * test: 💍 fix all tests in ui/admin * test: 💍 revert one change * refactor: 💡 update ui/desktop w/ feedback + fix tests * refactor: 💡 add in error handling * refactor: 💡 cleanup unused service * test: 💍 fix e2e test selector ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-17231
This commit is contained in:
1 parent
838bc37243
commit
72f7c8a92d
195 files changed
+720
-1112
No files matched your search
@@ -8,6 +8,7 @@ import { trait } from 'miragejs';
|
||||
import permissions from '../helpers/permissions';
|
||||
import generateId from '../helpers/id';
|
||||
import { faker } from '@faker-js/faker';
|
||||
import { TYPE_AUTH_METHOD_PASSWORD } from 'api/models/auth-method';
|
||||
|
||||
export default factory.extend({
|
||||
type: 'global',
|
||||
@@ -108,4 +109,21 @@ export default factory.extend({
|
||||
}
|
||||
},
|
||||
}),
|
||||
|
||||
withGlobalAuth: trait({
|
||||
afterCreate(record, server) {
|
||||
if (record.type === 'global') {
|
||||
const authMethod = server.create('auth-method', {
|
||||
type: TYPE_AUTH_METHOD_PASSWORD,
|
||||
scope: record,
|
||||
});
|
||||
server.create('account', {
|
||||
type: TYPE_AUTH_METHOD_PASSWORD,
|
||||
full_name: 'admin',
|
||||
scope: record,
|
||||
authMethod,
|
||||
});
|
||||
}
|
||||
},
|
||||
}),
|
||||
});
|
||||
@@ -13,7 +13,7 @@ const oidcRequiredAttempts = 3;
|
||||
|
||||
const commandHandlers = {
|
||||
password: {
|
||||
login: (payload, scopeAttrs) => {
|
||||
login: (payload, auth_method_id, account_id, scopeAttrs) => {
|
||||
if (payload.attributes.login_name === 'error') {
|
||||
return new Response(400);
|
||||
} else {
|
||||
@@ -25,9 +25,9 @@ const commandHandlers = {
|
||||
scope: scopeAttrs,
|
||||
id: 'token123',
|
||||
token: 'thetokenstring',
|
||||
account_id: 'authenticatedaccount',
|
||||
account_id: account_id || 'authenticatedaccount',
|
||||
user_id: 'authenticateduser',
|
||||
auth_method_id: 'authmethod123',
|
||||
auth_method_id: auth_method_id || 'authmethod123',
|
||||
created_time: '',
|
||||
updated_time: '',
|
||||
last_used_time: '',
|
||||
@@ -61,7 +61,7 @@ const commandHandlers = {
|
||||
},
|
||||
},
|
||||
),
|
||||
token: (_, scopeAttrs) => {
|
||||
token: (_, auth_method_id, account_id, scopeAttrs) => {
|
||||
oidcAttemptCounter++;
|
||||
if (oidcAttemptCounter < oidcRequiredAttempts) {
|
||||
return new Response(202);
|
||||
@@ -74,9 +74,9 @@ const commandHandlers = {
|
||||
scope: scopeAttrs,
|
||||
id: 'token123',
|
||||
token: 'thetokenstring',
|
||||
account_id: '1',
|
||||
account_id: account_id || '1',
|
||||
user_id: 'authenticateduser',
|
||||
auth_method_id: 'authmethod123',
|
||||
auth_method_id: auth_method_id || 'authmethod123',
|
||||
created_time: '',
|
||||
updated_time: '',
|
||||
last_used_time: '',
|
||||
@@ -90,7 +90,7 @@ const commandHandlers = {
|
||||
};
|
||||
|
||||
// Handles all custom methods on /auth-methods/:id route
|
||||
export function authHandler({ scopes, authMethods }, request) {
|
||||
export function authHandler({ scopes, authMethods, accounts }, request) {
|
||||
const [, id, method] = request.params.id_method.match(
|
||||
/(?<id>.[^:]*):(?<method>(.*))/,
|
||||
);
|
||||
@@ -100,8 +100,14 @@ export function authHandler({ scopes, authMethods }, request) {
|
||||
const payload = JSON.parse(request.requestBody);
|
||||
const { command } = payload;
|
||||
const scope = scopes.find(authMethod.scopeId);
|
||||
const account = accounts.where({ authMethodId: authMethod.id })?.models[0];
|
||||
const scopeAttrs = this.serialize(scopes.find(scope.id));
|
||||
return commandHandlers[authMethod.type][command](payload, scopeAttrs);
|
||||
return commandHandlers[authMethod.type][command](
|
||||
payload,
|
||||
authMethod.id,
|
||||
account?.id,
|
||||
scopeAttrs,
|
||||
);
|
||||
}
|
||||
|
||||
// TODO: this handler doesn't really belong here, but we already route
|
||||
|
||||
Reference in new issue
Block a user