[ARVADOS-WORKBENCH2] updated: 6e6ef73c3a75b2cfb6d0ee11827630ca46266982

Git user git at public.curoverse.com
Tue Jun 5 02:35:06 EDT 2018


Summary of changes:
 src/common/server-api.ts                  | 21 +++++++++++++++++++++
 src/services/auth-service/auth-service.ts |  9 ++++++---
 src/store/auth-reducer.ts                 |  5 +++++
 3 files changed, 32 insertions(+), 3 deletions(-)
 create mode 100644 src/common/server-api.ts

       via  6e6ef73c3a75b2cfb6d0ee11827630ca46266982 (commit)
      from  6e4ce0e45818dac7d6abc6456e85d49798d16458 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 6e6ef73c3a75b2cfb6d0ee11827630ca46266982
Author: Daniel Kos <daniel.kos at contractors.roche.com>
Date:   Tue Jun 5 08:34:59 2018 +0200

    Add server api instance
    
    Feature #13563
    
    Arvados-DCO-1.1-Signed-off-by: Daniel Kos <daniel.kos at contractors.roche.com>:

diff --git a/src/common/server-api.ts b/src/common/server-api.ts
new file mode 100644
index 0000000..9078b73
--- /dev/null
+++ b/src/common/server-api.ts
@@ -0,0 +1,21 @@
+// Copyright (C) The Arvados Authors. All rights reserved.
+//
+// SPDX-License-Identifier: AGPL-3.0
+
+import Axios, { AxiosInstance } from "axios";
+
+export const API_HOST = 'https://qr1hi.arvadosapi.com/arvados/v1';
+
+export const serverApi: AxiosInstance = Axios.create({
+    baseURL: API_HOST
+});
+
+export function setServerApiAuthorizationHeader(token: string) {
+    serverApi.defaults.headers.common = {
+        'Authorization': `OAuth2 ${token}`
+    };
+}
+
+export function removeServerApiAuthorizationHeader() {
+    delete serverApi.defaults.headers.common.Authorization;
+}
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index 11594c9..672a619 100644
--- a/src/services/auth-service/auth-service.ts
+++ b/src/services/auth-service/auth-service.ts
@@ -2,8 +2,10 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
+import Axios from "axios";
+import { API_HOST, serverApi } from "../../common/server-api";
+
 const API_TOKEN_KEY = 'api_token';
-const API_HOST = 'https://qr1hi.arvadosapi.com';
 
 export default class AuthService {
 
@@ -28,7 +30,8 @@ export default class AuthService {
         window.location.href = `${API_HOST}/login?return_to=${currentUrl}`;
     }
 
-    public logout() {
-        this.removeApiToken();
+    public logout(): Promise<any> {
+        const currentUrl = `${window.location.protocol}//${window.location.host}`;
+        return Axios.get(`${API_HOST}/logout?return_to=${currentUrl}`);
     }
 }
diff --git a/src/store/auth-reducer.ts b/src/store/auth-reducer.ts
index ec12d65..8e9eb4f 100644
--- a/src/store/auth-reducer.ts
+++ b/src/store/auth-reducer.ts
@@ -6,6 +6,7 @@ import { getType } from "typesafe-actions";
 import actions, { AuthAction } from "./auth-action";
 import { User } from "../models/user";
 import { authService } from "../services/services";
+import { removeServerApiAuthorizationHeader, serverApi, setServerApiAuthorizationHeader } from "../common/server-api";
 
 type AuthState = User | {};
 
@@ -13,6 +14,8 @@ const authReducer = (state: AuthState = {}, action: AuthAction) => {
     switch (action.type) {
         case getType(actions.saveApiToken): {
             authService.saveApiToken(action.payload);
+            setServerApiAuthorizationHeader(action.payload);
+            serverApi.get('/users/current');
             return {...state, apiToken: action.payload};
         }
         case getType(actions.login): {
@@ -20,6 +23,8 @@ const authReducer = (state: AuthState = {}, action: AuthAction) => {
             return state;
         }
         case getType(actions.logout): {
+            authService.removeApiToken();
+            removeServerApiAuthorizationHeader();
             authService.logout();
             return {...state, apiToken: null };
         }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list