15064: create iframes that load /fedtoken with salted token
[arvados-workbench2.git] / src / views / workbench / fed-login.tsx
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>;
         }
     });