var token = urlParams.get('token');
if (token) {
history.replaceState(null, "", `/webshell/?host=${encodeURIComponent(urlParams.get('host'))}&login=${encodeURIComponent(urlParams.get('login'))}`)
+ } else if (localStorage.getItem('apiToken')) {
+ token = localStorage.getItem('apiToken');
+ } else {
+ // No token
}
// change this text when PAM is reconfigured to present a
// password prompt that we can wait for.
export const USER_USERNAME = 'username';
export const USER_PREFS = 'prefs';
export const HOME_CLUSTER = 'homeCluster';
+export const LOCAL_STORAGE = 'localStorage';
+export const SESSION_STORAGE = 'sessionStorage';
export interface UserDetailsResponse {
email: string;
return localStorage;
}
+ public getStorageType() {
+ if (this.useSessionStorage) {
+ return SESSION_STORAGE;
+ }
+ return LOCAL_STORAGE;
+ }
+
public saveApiToken(token: string) {
this.removeApiToken();
this.getStorage().setItem(API_TOKEN_KEY, token);
SET_CONFIG: ofType<{ config: Config }>(),
SET_EXTRA_TOKEN: ofType<{ extraApiToken: string, extraApiTokenExpiration?: Date }>(),
RESET_EXTRA_TOKEN: {},
- INIT_USER: ofType<{ user: User, token: string, tokenExpiration?: Date }>(),
+ INIT_USER: ofType<{ user: User, token: string, tokenExpiration?: Date, tokenLocation?: string }>(),
USER_DETAILS_REQUEST: {},
USER_DETAILS_SUCCESS: ofType<User>(),
SET_SSH_KEYS: ofType<SshKeyResource[]>(),
const user = await svc.authService.getUserDetails();
const client = await svc.apiClientAuthorizationService.get('current');
const tokenExpiration = client.expiresAt ? new Date(client.expiresAt) : undefined;
- dispatch(authActions.INIT_USER({ user, token, tokenExpiration }));
+ const tokenLocation = await svc.authService.getStorageType();
+ dispatch(authActions.INIT_USER({ user, token, tokenExpiration, tokenLocation }));
} catch (e) {
dispatch(authActions.LOGOUT({ deleteLinkData: false }));
}
user?: User;
apiToken?: string;
apiTokenExpiration?: Date;
+ apiTokenLocation?: string;
extraApiToken?: string;
extraApiTokenExpiration?: Date;
sshKeys: SshKeyResource[];
user: undefined,
apiToken: undefined,
apiTokenExpiration: undefined,
+ apiTokenLocation: undefined,
extraApiToken: undefined,
extraApiTokenExpiration: undefined,
sshKeys: [],
({ ...state, extraApiToken, extraApiTokenExpiration }),
RESET_EXTRA_TOKEN: () =>
({ ...state, extraApiToken: undefined, extraApiTokenExpiration: undefined }),
- INIT_USER: ({ user, token, tokenExpiration }) =>
+ INIT_USER: ({ user, token, tokenExpiration, tokenLocation = state.apiTokenLocation }) =>
({ ...state,
user,
apiToken: token,
apiTokenExpiration: tokenExpiration,
+ apiTokenLocation: tokenLocation,
homeCluster: user.uuid.substr(0, 5)
}),
LOGIN: () => state,
import { RootState } from 'store/store';
import { ListResults } from 'services/common-service/common-service';
import { HelpIcon } from 'components/icon/icon';
+import { SESSION_STORAGE } from "services/auth-service/auth-service";
// import * as CopyToClipboard from 'react-copy-to-clipboard';
type CssRules = 'button' | 'codeSnippet' | 'link' | 'linkIcon' | 'rightAlign' | 'cardWithoutMachines' | 'icon';
+const EXTRA_TOKEN = "exra";
+
const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
button: {
marginTop: theme.spacing.unit,
helpText: state.auth.config.clusterConfig.Workbench.SSHHelpPageHTML,
hostSuffix: state.auth.config.clusterConfig.Workbench.SSHHelpHostSuffix || "",
token: state.auth.extraApiToken || state.auth.apiToken || '',
+ tokenLocation: state.auth.extraApiToken ? EXTRA_TOKEN : (state.auth.apiTokenLocation || ''),
webshellUrl: state.auth.config.clusterConfig.Services.WebShell.ExternalURL,
...state.virtualMachines
};
helpText: string;
hostSuffix: string;
token: string;
+ tokenLocation: string,
webshellUrl: string;
}
if (lk.tailUuid === props.userUuid) {
const username = lk.properties.username;
const command = `ssh ${username}@${it.hostname}${props.hostSuffix}`;
+ let tokenParam = "";
+ if (props.tokenLocation === SESSION_STORAGE || props.tokenLocation === EXTRA_TOKEN) {
+ tokenParam = `&token=${encodeURIComponent(props.token)}`;
+ }
return <TableRow key={lk.uuid}>
<TableCell>{it.hostname}</TableCell>
<TableCell>{username}</TableCell>
{command}
</TableCell>
<TableCell>
- <a href={`/webshell/?host=${encodeURIComponent(props.webshellUrl + '/' + it.hostname)}&login=${username}&token=${encodeURIComponent(props.token)}`} target="_blank" rel="noopener noreferrer" className={props.classes.link}>
+ <a href={`/webshell/?host=${encodeURIComponent(props.webshellUrl + '/' + it.hostname)}&login=${encodeURIComponent(username)}${tokenParam}`} target="_blank" rel="noopener noreferrer" className={props.classes.link}>
Log in as {username}
</a>
</TableCell>