projects
/
arvados-workbench2.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
16812: Handoff token using query param
[arvados-workbench2.git]
/
src
/
store
/
auth
/
auth-action-session.ts
diff --git
a/src/store/auth/auth-action-session.ts
b/src/store/auth/auth-action-session.ts
index 0f85e9ac5005fe5de7274d2dbe5d8526a9cfa81d..a02f922df435d9f0b1c9065ef9a9e9f4a317ebd6 100644
(file)
--- a/
src/store/auth/auth-action-session.ts
+++ b/
src/store/auth/auth-action-session.ts
@@
-6,7
+6,7
@@
import { Dispatch } from "redux";
import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
import { RootState } from "~/store/store";
import { ServiceRepository, createServices, setAuthorizationHeader } from "~/services/services";
import { setBreadcrumbs } from "~/store/breadcrumbs/breadcrumbs-actions";
import { RootState } from "~/store/store";
import { ServiceRepository, createServices, setAuthorizationHeader } from "~/services/services";
-import Axios from "axios";
+import Axios
, { AxiosInstance }
from "axios";
import { User, getUserDisplayName } from "~/models/user";
import { authActions } from "~/store/auth/auth-action";
import {
import { User, getUserDisplayName } from "~/models/user";
import { authActions } from "~/store/auth/auth-action";
import {
@@
-20,13
+20,14
@@
import { AuthService } from "~/services/auth-service/auth-service";
import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
import * as jsSHA from "jssha";
import { snackbarActions, SnackbarKind } from "~/store/snackbar/snackbar-actions";
import * as jsSHA from "jssha";
-const getClusterConfig = async (origin: string): Promise<Config | null> => {
+const getClusterConfig = async (origin: string
, apiClient: AxiosInstance
): Promise<Config | null> => {
let configFromDD: Config | undefined;
try {
let configFromDD: Config | undefined;
try {
- const dd = (await
Axios
.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
+ const dd = (await
apiClient
.get<any>(`${origin}/${DISCOVERY_DOC_PATH}`)).data;
configFromDD = {
baseUrl: normalizeURLPath(dd.baseUrl),
keepWebServiceUrl: dd.keepWebServiceUrl,
configFromDD = {
baseUrl: normalizeURLPath(dd.baseUrl),
keepWebServiceUrl: dd.keepWebServiceUrl,
+ keepWebInlineServiceUrl: dd.keepWebInlineServiceUrl,
remoteHosts: dd.remoteHosts,
rootUrl: dd.rootUrl,
uuidPrefix: dd.uuidPrefix,
remoteHosts: dd.remoteHosts,
rootUrl: dd.rootUrl,
uuidPrefix: dd.uuidPrefix,
@@
-41,9
+42,9
@@
const getClusterConfig = async (origin: string): Promise<Config | null> => {
};
} catch { }
};
} catch { }
- // Try
the new
public config endpoint
+ // Try public config endpoint
try {
try {
- const config = (await
Axios
.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
+ const config = (await
apiClient
.get<ClusterConfigJSON>(`${origin}/${CLUSTER_CONFIG_PATH}`)).data;
return { ...buildConfig(config), apiRevision: configFromDD ? configFromDD.apiRevision : 0 };
} catch { }
return { ...buildConfig(config), apiRevision: configFromDD ? configFromDD.apiRevision : 0 };
} catch { }
@@
-55,7
+56,9
@@
const getClusterConfig = async (origin: string): Promise<Config | null> => {
return null;
};
return null;
};
-const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> => {
+const getRemoteHostConfig = async (remoteHost: string, useApiClient?: AxiosInstance): Promise<Config | null> => {
+ const apiClient = useApiClient || Axios.create({ headers: {} });
+
let url = remoteHost;
if (url.indexOf('://') < 0) {
url = 'https://' + url;
let url = remoteHost;
if (url.indexOf('://') < 0) {
url = 'https://' + url;
@@
-63,14
+66,14
@@
const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> =
const origin = new URL(url).origin;
// Maybe it is an API server URL, try fetching config and discovery doc
const origin = new URL(url).origin;
// Maybe it is an API server URL, try fetching config and discovery doc
- let r = await getClusterConfig(origin);
+ let r = await getClusterConfig(origin
, apiClient
);
if (r !== null) {
return r;
}
// Maybe it is a Workbench2 URL, try getting config.json
try {
if (r !== null) {
return r;
}
// Maybe it is a Workbench2 URL, try getting config.json
try {
- r = await getClusterConfig((await
Axios.get<any>(`${origin}/config.json`)).data.API_HOST
);
+ r = await getClusterConfig((await
apiClient.get<any>(`${origin}/config.json`)).data.API_HOST, apiClient
);
if (r !== null) {
return r;
}
if (r !== null) {
return r;
}
@@
-78,7
+81,7
@@
const getRemoteHostConfig = async (remoteHost: string): Promise<Config | null> =
// Maybe it is a Workbench1 URL, try getting status.json
try {
// Maybe it is a Workbench1 URL, try getting status.json
try {
- r = await getClusterConfig((await
Axios.get<any>(`${origin}/status.json`)).data.apiBaseURL
);
+ r = await getClusterConfig((await
apiClient.get<any>(`${origin}/status.json`)).data.apiBaseURL, apiClient
);
if (r !== null) {
return r;
}
if (r !== null) {
return r;
}
@@
-121,7
+124,7
@@
export const validateCluster = async (config: Config, useToken: string):
};
};
};
};
-export const validateSession = (session: Session, activeSession: Session) =>
+export const validateSession = (session: Session, activeSession: Session
, useApiClient?: AxiosInstance
) =>
async (dispatch: Dispatch): Promise<Session> => {
dispatch(authActions.UPDATE_SESSION({ ...session, status: SessionStatus.BEING_VALIDATED }));
session.loggedIn = false;
async (dispatch: Dispatch): Promise<Session> => {
dispatch(authActions.UPDATE_SESSION({ ...session, status: SessionStatus.BEING_VALIDATED }));
session.loggedIn = false;
@@
-130,6
+133,7
@@
export const validateSession = (session: Session, activeSession: Session) =>
session.baseUrl = baseUrl;
session.token = token;
session.email = user.email;
session.baseUrl = baseUrl;
session.token = token;
session.email = user.email;
+ session.userIsActive = user.isActive;
session.uuid = user.uuid;
session.name = getUserDisplayName(user);
session.loggedIn = true;
session.uuid = user.uuid;
session.name = getUserDisplayName(user);
session.loggedIn = true;
@@
-137,7
+141,7
@@
export const validateSession = (session: Session, activeSession: Session) =>
};
let fail: Error | null = null;
};
let fail: Error | null = null;
- const config = await getRemoteHostConfig(session.remoteHost);
+ const config = await getRemoteHostConfig(session.remoteHost
, useApiClient
);
if (config !== null) {
dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config }));
try {
if (config !== null) {
dispatch(authActions.REMOTE_CLUSTER_CONFIG({ config }));
try {
@@
-168,7
+172,7
@@
export const validateSession = (session: Session, activeSession: Session) =>
return session;
};
return session;
};
-export const validateSessions = () =>
+export const validateSessions = (
useApiClient?: AxiosInstance
) =>
async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
const sessions = getState().auth.sessions;
const activeSession = getActiveSession(sessions);
async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
const sessions = getState().auth.sessions;
const activeSession = getActiveSession(sessions);
@@
-186,12
+190,13
@@
export const validateSessions = () =>
override it using Dispatch<any>. This
pattern is used in a bunch of different
places in Workbench2. */
override it using Dispatch<any>. This
pattern is used in a bunch of different
places in Workbench2. */
- await dispatch(validateSession(session, activeSession));
+ await dispatch(validateSession(session, activeSession
, useApiClient
));
} catch (e) {
} catch (e) {
- dispatch(snackbarActions.OPEN_SNACKBAR({
- message: e.message,
- kind: SnackbarKind.ERROR
- }));
+ // Don't do anything here. User may get
+ // spammed with multiple messages that are not
+ // helpful. They can see the individual
+ // errors by going to site manager and trying
+ // to toggle the session.
}
}
}
}
}
}
@@
-242,6
+247,7
@@
export const addSession = (remoteHost: string, token?: string, sendToLogin?: boo
status: SessionStatus.VALIDATED,
active: false,
email: user.email,
status: SessionStatus.VALIDATED,
active: false,
email: user.email,
+ userIsActive: user.isActive,
name: getUserDisplayName(user),
uuid: user.uuid,
baseUrl: config.baseUrl,
name: getUserDisplayName(user),
uuid: user.uuid,
baseUrl: config.baseUrl,
@@
-309,7
+315,7
@@
export const initSessions = (authService: AuthService, config: Config, user: Use
(dispatch: Dispatch<any>) => {
const sessions = authService.buildSessions(config, user);
dispatch(authActions.SET_SESSIONS(sessions));
(dispatch: Dispatch<any>) => {
const sessions = authService.buildSessions(config, user);
dispatch(authActions.SET_SESSIONS(sessions));
- dispatch(validateSessions());
+ dispatch(validateSessions(
authService.getApiClient()
));
};
export const loadSiteManagerPanel = () =>
};
export const loadSiteManagerPanel = () =>