refs #13989 Merge branch 'origin/13989-webdav-service'
[arvados-workbench2.git] / src / store / auth / auth-action.ts
index 9f429f0537034a2fc34c7a582b52e62378aafccf..33a5df90450e2cde772c73c8d80c7b06854c4f12 100644 (file)
@@ -17,12 +17,15 @@ export const authActions = unionize({
     USER_DETAILS_REQUEST: {},
     USER_DETAILS_SUCCESS: ofType<User>()
 }, {
-    tag: 'type',
-    value: 'payload'
-});
+        tag: 'type',
+        value: 'payload'
+    });
 
-function setAuthorizationHeader(client: AxiosInstance, token: string) {
-    client.defaults.headers.common = {
+function setAuthorizationHeader(services: ServiceRepository, token: string) {
+    services.apiClient.defaults.headers.common = {
+        Authorization: `OAuth2 ${token}`
+    };
+    services.webdavClient.defaults.headers = {
         Authorization: `OAuth2 ${token}`
     };
 }
@@ -35,7 +38,7 @@ export const initAuth = () => (dispatch: Dispatch, getState: () => RootState, se
     const user = services.authService.getUser();
     const token = services.authService.getApiToken();
     if (token) {
-        setAuthorizationHeader(services.apiClient, token);
+        setAuthorizationHeader(services, token);
     }
     if (token && user) {
         dispatch(authActions.INIT({ user, token }));
@@ -44,7 +47,7 @@ export const initAuth = () => (dispatch: Dispatch, getState: () => RootState, se
 
 export const saveApiToken = (token: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
     services.authService.saveApiToken(token);
-    setAuthorizationHeader(services.apiClient, token);
+    setAuthorizationHeader(services, token);
     dispatch(authActions.SAVE_API_TOKEN(token));
 };