chore: Rebase onto feature-oidc-array-fields-crud branch

This commit is contained in:
Susmitha Girumala committed 2021-06-02 14:03:53 -04:00
1 parent 44fa206619
commit a6672ecef4
6 files changed
+69 -78

No files matched your search

+4 -28
View File
@@ -1,6 +1,6 @@
import Ember from 'ember';
import config from '../config/environment';
import { deauthHandler } from './route-handlers/auth';
import { authHandler, deauthHandler } from './route-handlers/auth';
import { pickRandomStatusString } from './factories/session';
import { Response } from 'miragejs';
import initializeMockIPC from './scenarios/ipc';
@@ -71,31 +71,6 @@ export default function () {
}
return new Response(202);
});
this.post('/auth-methods/:idMethod', function (schema, request) {
const idMethod = request.params.idMethod;
const id = idMethod.split(':')[0];
const method = idMethod.split(':')[1];
if (method === 'authenticate') {
schema.authHandler.call(this, schema, request);
return;
}
const attrs = this.normalizedRequestAttrs();
const authMethods = schema.authMethods;
const authMethod = authMethods.find(id);
let updatedAttrs = {};
if (method === 'change-state') {
updatedAttrs = {
attributes: {
state: attrs.attributes.state,
},
};
}
return authMethod.update(updatedAttrs);
});
// Auth Method Accounts
this.get(
@@ -131,8 +106,9 @@ export default function () {
}
);
// Authenticate/deauthenticate routes
// this.post('/auth-methods/:id_method', authHandler);
// Authenticate + auth methods custom routes
this.post('/auth-methods/:id_method', authHandler);
// Deauthenticate route
this.post('/scopes/:id_method', deauthHandler);
// IAM : Users
+27 -6
View File
@@ -107,14 +107,35 @@ const commandHandlers = {
},
};
// Handles all custom methods on /auth-methods/:id route
export function authHandler({ scopes, authMethods }, request) {
const payload = JSON.parse(request.requestBody);
const [, id] = request.params.idMethod.match(/(?<id>.[^:]*)/);
const { command } = payload;
const [, id, method] = request.params.id_method.match(
/(?<id>.[^:]*):(?<method>(.*))/
);
const authMethod = authMethods.find(id);
const scope = scopes.find(authMethod.scopeId);
const scopeAttrs = this.serialize(scopes.find(scope.id));
return commandHandlers[authMethod.type][command](payload, scopeAttrs);
if (method === 'authenticate') {
const payload = JSON.parse(request.requestBody);
const { command } = payload;
const scope = scopes.find(authMethod.scopeId);
const scopeAttrs = this.serialize(scopes.find(scope.id));
return commandHandlers[authMethod.type][command](payload, scopeAttrs);
}
if (method === 'change-state') {
const attrs = this.normalizedRequestAttrs();
let updatedAttrs = {};
if (method === 'change-state') {
updatedAttrs = {
attributes: {
state: attrs.attributes.state,
},
};
}
return authMethod.update(updatedAttrs);
}
}
export function deauthHandler() {
-6
View File
@@ -1,5 +1,3 @@
import { authHandler } from '../route-handlers/auth';
export default function (server) {
// Scope resources
@@ -52,8 +50,4 @@ export default function (server) {
server.createList('target', 2, { scope }, 'withRandomHostSets');
server.createList('session', 4, { scope }, 'withAssociations');
});
// Authenticate route handler
// TODO: Better way to pass-in auth handler
server.schema.authHandler = authHandler;
}