refactor: 💡 auth payloads now have "attributes" field

This commit is contained in:
Randall Morey committed 2021-04-01 17:41:30 -04:00
1 parent 6927008041
commit 3d13d8f412
11 files changed
+74 -218

No files matched your search

+8 -3
View File
@@ -72,9 +72,10 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator {
*/
async restore(data) {
if (!data) return reject();
return this.validateToken(data.token, data.id).then(() =>
this.normalizeData(data)
);
return this.validateToken(
data.attributes.token,
data.attributes.id
).then(() => this.normalizeData(data));
}
/**
@@ -86,6 +87,10 @@ export default class BaseAuthenticator extends SimpleAuthBaseAuthenticator {
* @return {object}
*/
normalizeData(data, username) {
// Pull fields up from `data.attributes` for easier access in JavaScript.
// The `attributes` field exists on the Go side for its convenience but is
// unnecessary here.
Object.assign(data, data.attributes);
// Add booleans indicated the scope type
data.isGlobal = data?.scope?.type === 'global';
data.isOrg = data?.scope?.type === 'org';
+6 -2
View File
@@ -83,8 +83,12 @@ export default class OIDCAuthenticator extends BaseAuthenticator {
const url = this.buildAuthEndpointURL(options);
const body = JSON.stringify({
command: 'token',
state: this.session.get('data.pending.oidc.state'),
token_request_id: this.session.get('data.pending.oidc.token_request_id'),
attributes: {
state: this.session.get('data.pending.oidc.state'),
token_request_id: this.session.get(
'data.pending.oidc.token_request_id'
),
},
});
// Fetch the endpoint and get the response JSON
const response = await fetch(url, { method: 'post', body });
+1 -1
View File
@@ -58,7 +58,7 @@ export default class PasswordAuthenticator extends BaseAuthenticator {
const body = JSON.stringify({
command: 'login',
token_type: requestCookies ? 'cookie' : null,
credentials: { login_name, password },
attributes: { login_name, password },
});
const authEndpointURL = this.buildAuthEndpointURL(options);
const response = await fetch(authEndpointURL, { method: 'post', body });