15064: create iframes that load /fedtoken with salted token
authorPeter Amstutz <pamstutz@veritasgenetics.com>
Mon, 13 May 2019 16:29:04 +0000 (12:29 -0400)
committerPeter Amstutz <pamstutz@veritasgenetics.com>
Mon, 13 May 2019 16:50:16 +0000 (12:50 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <pamstutz@veritasgenetics.com>

src/common/config.ts
src/views/workbench/fed-login.tsx

index 7abff5dab0750f03136881f81ba6714e8f763d17..71b7774c5fa8d765818b7ce611f6e4bfa1805c11 100644 (file)
@@ -137,4 +137,4 @@ const getDefaultConfig = (): ConfigJSON => ({
 });
 
 export const DISCOVERY_URL = 'discovery/v1/apis/arvados/v1/rest';
-export const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/${DISCOVERY_URL}`;
+export const getDiscoveryURL = (apiHost: string) => `${window.location.protocol}//${apiHost}/${DISCOVERY_URL}?nocache=${(new Date()).getTime()}`;
index 0e9b5308c5d06c5405ce084fd1a2263c4aebcc9c..399b419eed26c0ef66e4cf78ec2a75cd3480bfe0 100644 (file)
@@ -6,26 +6,41 @@ import * as React from 'react';
 import { connect } from 'react-redux';
 import { RootState } from '~/store/store';
 import { AuthState } from '~/store/auth/auth-reducer';
+import { User } from "~/models/user";
 import { getSaltedToken } from '~/store/auth/auth-action-session';
+import { Config } from '~/common/config';
 
 export interface FedLoginProps {
-    auth: AuthState;
+    user?: User;
+    apiToken?: string;
+    homeCluster: string;
+    remoteHostsConfig: { [key: string]: Config };
 }
 
-const mapStateToProps = ({ auth }: RootState) => ({ auth });
+const mapStateToProps = ({ auth }: RootState) => ({
+    user: auth.user,
+    apiToken: auth.apiToken,
+    remoteHostsConfig: auth.remoteHostsConfig,
+    homeCluster: auth.homeCluster,
+});
 
 export const FedLogin = connect(mapStateToProps)(
     class extends React.Component<FedLoginProps> {
         render() {
-            const auth = this.props.auth;
-            const remoteHostsConfig = auth.remoteHostsConfig;
-            if (!auth.user || !auth.user.uuid.startsWith(auth.homeCluster)) {
+            const { apiToken, user, homeCluster, remoteHostsConfig } = this.props;
+            if (!apiToken || !user || !user.uuid.startsWith(homeCluster)) {
                 return <></>;
             }
-            return <div>
+            const [, tokenUuid, token] = apiToken.split("/");
+            return <div id={"fedtoken-iframe-div"}>
                 {Object.keys(remoteHostsConfig)
-                    .filter((k) => k !== auth.homeCluster)
-                    .map((k) => <iframe key={k} src={"https://" + remoteHostsConfig[k].workbench2Url} style={{ visibility: "hidden" }} />)}
+                    .map((k) => k !== homeCluster &&
+                        <iframe key={k} src={`${remoteHostsConfig[k].workbench2Url}/fedtoken?api_token=${getSaltedToken(k, tokenUuid, token)}`} style={{
+                            height: 0,
+                            width: 0,
+                            visibility: "hidden"
+                        }}
+                        />)}
             </div>;
         }
     });