deb.open-vault/ui/app/models/role-jwt.js

36 lines
931 B
JavaScript
Raw Normal View History

2024-04-20 12:23:50 +00:00
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import Model, { attr } from '@ember-data/model';
import parseURL from 'core/utils/parse-url';
const DOMAIN_STRINGS = {
'github.com': 'GitHub',
'gitlab.com': 'GitLab',
'google.com': 'Google',
'ping.com': 'Ping',
'okta.com': 'Okta',
'auth0.com': 'Auth0',
};
const PROVIDER_WITH_LOGO = ['GitLab', 'Google', 'Auth0'];
export { DOMAIN_STRINGS, PROVIDER_WITH_LOGO };
export default class RoleJwtModel extends Model {
@attr('string') authUrl;
get providerName() {
const { hostname } = parseURL(this.authUrl);
const firstMatch = Object.keys(DOMAIN_STRINGS).find((name) => hostname.includes(name));
return DOMAIN_STRINGS[firstMatch] || null;
}
get providerButtonComponent() {
const { providerName } = this;
return PROVIDER_WITH_LOGO.includes(providerName) ? `auth-button-${providerName.toLowerCase()}` : null;
}
}