feat: update keycloak theme
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
||||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
||||
/*
|
||||
* Copyright 2018 Red Hat Inc. and/or its affiliates and other contributors
|
||||
* as indicated by the @author tags. All rights reserved.
|
||||
@@ -16,71 +17,64 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
import { ContentAlert } from "../content/ContentAlert.js";
|
||||
export class AccountServiceError extends Error {
|
||||
constructor(response) {
|
||||
super(response.statusText);
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stan Silvert ssilvert@redhat.com (C) 2018 Red Hat Inc.
|
||||
*/
|
||||
|
||||
export class AccountServiceClient {
|
||||
constructor(keycloakService) {
|
||||
_defineProperty(this, "kcSvc", void 0);
|
||||
|
||||
_defineProperty(this, "accountUrl", void 0);
|
||||
|
||||
this.kcSvc = keycloakService;
|
||||
this.accountUrl = this.kcSvc.authServerUrl() + 'realms/' + this.kcSvc.realm() + '/account';
|
||||
}
|
||||
|
||||
async doGet(endpoint, config) {
|
||||
return this.doRequest(endpoint, { ...config,
|
||||
return this.doRequest(endpoint, {
|
||||
...config,
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
async doDelete(endpoint, config) {
|
||||
return this.doRequest(endpoint, { ...config,
|
||||
return this.doRequest(endpoint, {
|
||||
...config,
|
||||
method: 'delete'
|
||||
});
|
||||
}
|
||||
|
||||
async doPost(endpoint, body, config) {
|
||||
return this.doRequest(endpoint, { ...config,
|
||||
return this.doRequest(endpoint, {
|
||||
...config,
|
||||
body: JSON.stringify(body),
|
||||
method: 'post'
|
||||
});
|
||||
}
|
||||
|
||||
async doPut(endpoint, body, config) {
|
||||
return this.doRequest(endpoint, { ...config,
|
||||
return this.doRequest(endpoint, {
|
||||
...config,
|
||||
body: JSON.stringify(body),
|
||||
method: 'put'
|
||||
});
|
||||
}
|
||||
|
||||
async doRequest(endpoint, config) {
|
||||
const response = await fetch(this.makeUrl(endpoint, config).toString(), await this.makeConfig(config));
|
||||
|
||||
try {
|
||||
response.data = await response.json();
|
||||
} catch (e) {} // ignore. Might be empty
|
||||
|
||||
|
||||
if (!response.ok) {
|
||||
this.handleError(response);
|
||||
throw new AccountServiceError(response);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
handleError(response) {
|
||||
if (response !== null && response.status === 401) {
|
||||
if (this.kcSvc.authenticated() && !this.kcSvc.audiencePresent()) {
|
||||
@@ -91,40 +85,36 @@ export class AccountServiceClient {
|
||||
this.kcSvc.login();
|
||||
}
|
||||
}
|
||||
|
||||
if (response !== null && response.status === 403) {
|
||||
window.location.href = baseUrl + '#/forbidden';
|
||||
}
|
||||
|
||||
if (response !== null && response.data != null) {
|
||||
if (response.data['errors'] != null) {
|
||||
for (let err of response.data['errors']) ContentAlert.danger(err['errorMessage'], err['params']);
|
||||
} else {
|
||||
ContentAlert.danger(`${response.statusText}: ${response.data['errorMessage'] ? response.data['errorMessage'] : ''} ${response.data['error'] ? response.data['error'] : ''}`);
|
||||
}
|
||||
|
||||
;
|
||||
} else {
|
||||
ContentAlert.danger(response.statusText);
|
||||
}
|
||||
}
|
||||
|
||||
makeUrl(endpoint, config) {
|
||||
if (endpoint.startsWith('http')) return new URL(endpoint);
|
||||
const url = new URL(this.accountUrl + endpoint); // add request params
|
||||
const url = new URL(this.accountUrl + endpoint);
|
||||
|
||||
// add request params
|
||||
if (config && config.hasOwnProperty('params')) {
|
||||
const params = config.params || {};
|
||||
Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
makeConfig(config = {}) {
|
||||
return new Promise(resolve => {
|
||||
this.kcSvc.getToken().then(token => {
|
||||
resolve({ ...config,
|
||||
resolve({
|
||||
...config,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
...config.headers,
|
||||
@@ -136,7 +126,6 @@ export class AccountServiceClient {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
window.addEventListener("unhandledrejection", event => {
|
||||
event.promise.catch(error => {
|
||||
|
||||
Reference in New Issue
Block a user