mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
019191c36b
Closes issue #1456 This PR adds a single sign on option to the login form, exposes single sign on to the end user, and allows an admin user to set single sign on configuration options.
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
import local from 'utilities/local';
|
|
import Request from 'kolide/request';
|
|
|
|
class Base {
|
|
constructor () {
|
|
const { origin } = global.window.location;
|
|
|
|
this.baseURL = `${origin}/api`;
|
|
this.bearerToken = local.getItem('auth_token');
|
|
}
|
|
|
|
static post (endpoint, body = {}, headers = {}) {
|
|
const { POST } = Request.REQUEST_METHODS;
|
|
|
|
return Base._request(POST, endpoint, body, headers);
|
|
}
|
|
|
|
static get (endpoint, overrideHeaders = {}) {
|
|
const { GET } = Request.REQUEST_METHODS;
|
|
return Base._request(GET, endpoint, {}, overrideHeaders);
|
|
}
|
|
|
|
static _deleteRequest (endpoint, headers) {
|
|
const { DELETE: method } = Request.REQUEST_METHODS;
|
|
const request = new Request({ endpoint, method, headers });
|
|
|
|
return request.send();
|
|
}
|
|
|
|
static _request (method, endpoint, body, headers) {
|
|
const { GET } = Request.REQUEST_METHODS;
|
|
const requestAttrs = method === GET
|
|
? { endpoint, method, headers }
|
|
: { endpoint, method, body, headers };
|
|
const request = new Request(requestAttrs);
|
|
|
|
return request.send();
|
|
}
|
|
|
|
_authenticatedHeaders = (headers) => {
|
|
return {
|
|
...headers,
|
|
Authorization: `Bearer ${this.bearerToken}`,
|
|
};
|
|
}
|
|
|
|
_authenticatedRequest(method, endpoint, body, overrideHeaders) {
|
|
const headers = this._authenticatedHeaders(overrideHeaders);
|
|
|
|
return Base._request(method, endpoint, body, headers);
|
|
}
|
|
|
|
_endpoint (pathname) {
|
|
return this.baseURL + pathname;
|
|
}
|
|
}
|
|
|
|
export default Base;
|