refs #14801-api-resonse-is-not-complete
[arvados-workbench2.git] / src / store / auth / auth-action-session.ts
index 4a6f56f92d9b4270f5a0e6065d3cf86aa4afe7e9..b32e205016a1824a8c6ed3554637ffac68b2b726 100644 (file)
@@ -12,7 +12,7 @@ import { authActions } from "~/store/auth/auth-action";
 import { Config, DISCOVERY_URL } from "~/common/config";
 import { Session, SessionStatus } from "~/models/session";
 import { progressIndicatorActions } from "~/store/progress-indicator/progress-indicator-actions";
-import { UserDetailsResponse } from "~/services/auth-service/auth-service";
+import { AuthService, UserDetailsResponse } from "~/services/auth-service/auth-service";
 import * as jsSHA from "jssha";
 
 const getRemoteHostBaseUrl = async (remoteHost: string): Promise<string | null> => {
@@ -56,7 +56,7 @@ const getTokenUuid = async (baseUrl: string, token: string): Promise<string> =>
         return Promise.resolve(uuid);
     }
 
-    const resp = await Axios.get(`${baseUrl}/api_client_authorizations`, {
+    const resp = await Axios.get(`${baseUrl}api_client_authorizations`, {
         headers: {
             Authorization: `OAuth2 ${token}`
         },
@@ -80,7 +80,7 @@ const getSaltedToken = (clusterId: string, tokenUuid: string, token: string) =>
     return `v2/${tokenUuid}/${hmac}`;
 };
 
-const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: Session): Promise<{user: User, token: string}> => {
+const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: Session): Promise<{ user: User, token: string }> => {
     const tokenUuid = await getTokenUuid(activeSession.baseUrl, activeSession.token);
     const saltedToken = getSaltedToken(clusterId, tokenUuid, activeSession.token);
     const user = await getUserDetails(baseUrl, saltedToken);
@@ -91,13 +91,15 @@ const clusterLogin = async (clusterId: string, baseUrl: string, activeSession: S
             uuid: user.uuid,
             ownerUuid: user.owner_uuid,
             email: user.email,
-            isAdmin: user.is_admin
+            isAdmin: user.is_admin,
+            identityUrl: user.identity_url,
+            prefs: user.prefs
         },
         token: saltedToken
     };
 };
 
-const getActiveSession = (sessions: Session[]): Session | undefined => sessions.find(s => s.active);
+export const getActiveSession = (sessions: Session[]): Session | undefined => sessions.find(s => s.active);
 
 export const validateCluster = async (remoteHost: string, clusterId: string, activeSession: Session): Promise<{ user: User; token: string, baseUrl: string }> => {
     const baseUrl = await getRemoteHostBaseUrl(remoteHost);
@@ -195,10 +197,17 @@ export const toggleSession = (session: Session) =>
         services.authService.saveSessions(getState().auth.sessions);
     };
 
+export const initSessions = (authService: AuthService, config: Config, user: User) =>
+    (dispatch: Dispatch<any>) => {
+        const sessions = authService.buildSessions(config, user);
+        authService.saveSessions(sessions);
+        dispatch(authActions.SET_SESSIONS(sessions));
+    };
+
 export const loadSiteManagerPanel = () =>
     async (dispatch: Dispatch<any>) => {
         try {
-            dispatch(setBreadcrumbs([{ label: 'Site Manager'}]));
+            dispatch(setBreadcrumbs([{ label: 'Site Manager' }]));
             dispatch(validateSessions());
         } catch (e) {
             return;