// SPDX-License-Identifier: AGPL-3.0
import Axios from "axios";
+import { AxiosInstance } from "axios";
import { ApiClientAuthorizationService } from '~/services/api-client-authorization-service/api-client-authorization-service';
import { AuthService } from "./auth-service/auth-service";
import { GroupsService } from "./groups-service/groups-service";
import { VocabularyService } from '~/services/vocabulary-service/vocabulary-service';
import { NodeService } from '~/services/node-service/node-service';
import { FileViewersConfigService } from '~/services/file-viewers-config-service/file-viewers-config-service';
+import { LinkAccountService } from "./link-account-service/link-account-service";
export type ServiceRepository = ReturnType<typeof createServices>;
-export const createServices = (config: Config, actions: ApiActions) => {
- const apiClient = Axios.create();
+export function setAuthorizationHeader(services: ServiceRepository, token: string) {
+ services.apiClient.defaults.headers.common = {
+ Authorization: `Bearer ${token}`
+ };
+ services.webdavClient.defaults.headers = {
+ Authorization: `Bearer ${token}`
+ };
+}
+
+export function removeAuthorizationHeader(services: ServiceRepository) {
+ delete services.apiClient.defaults.headers.common;
+ delete services.webdavClient.defaults.headers.common;
+}
+
+export const createServices = (config: Config, actions: ApiActions, useApiClient?: AxiosInstance) => {
+ // Need to give empty 'headers' object or it will create an
+ // instance with a reference to the global default headers object,
+ // which is very bad because that means setAuthorizationHeader
+ // would update the global default instead of the instance default.
+ const apiClient = useApiClient || Axios.create({ headers: {} });
apiClient.defaults.baseURL = config.baseUrl;
const webdavClient = new WebDAV();
const userService = new UserService(apiClient, actions);
const virtualMachineService = new VirtualMachinesService(apiClient, actions);
const workflowService = new WorkflowService(apiClient, actions);
+ const linkAccountService = new LinkAccountService(apiClient, actions);
const ancestorsService = new AncestorService(groupsService, userService);
const authService = new AuthService(apiClient, config.rootUrl, actions);
webdavClient,
workflowService,
vocabularyService,
+ linkAccountService
};
};