15255: Log missing workbench2Url value to console.
[arvados-workbench2.git] / src / views / workbench / fed-login.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { connect } from 'react-redux';
7 import { RootState } from '~/store/store';
8 import { AuthState } from '~/store/auth/auth-reducer';
9 import { User } from "~/models/user";
10 import { getSaltedToken } from '~/store/auth/auth-action-session';
11 import { Config } from '~/common/config';
12
13 export interface FedLoginProps {
14     user?: User;
15     apiToken?: string;
16     localCluster: string;
17     remoteHostsConfig: { [key: string]: Config };
18 }
19
20 const mapStateToProps = ({ auth }: RootState) => ({
21     user: auth.user,
22     apiToken: auth.apiToken,
23     remoteHostsConfig: auth.remoteHostsConfig,
24     localCluster: auth.localCluster,
25 });
26
27 export const FedLogin = connect(mapStateToProps)(
28     class extends React.Component<FedLoginProps> {
29         render() {
30             const { apiToken, user, localCluster, remoteHostsConfig } = this.props;
31             if (!apiToken || !user || !user.uuid.startsWith(localCluster)) {
32                 return <></>;
33             }
34             const [, tokenUuid, token] = apiToken.split("/");
35             return <div id={"fedtoken-iframe-div"}>
36                 {Object.keys(remoteHostsConfig)
37                     .map((k) => {
38                         if (k === localCluster) {
39                             return;
40                         }
41                         if (!remoteHostsConfig[k].workbench2Url) {
42                             console.log(`Cluster ${k} does not define workbench2Url.  Federated login / cross-site linking to ${k} is unavailable.  Tell the admin of ${k} to set Services->Workbench2->ExternalURL in config.yml.`);
43                             return;
44                         }
45                         return <iframe key={k} src={`${remoteHostsConfig[k].workbench2Url}/fedtoken?api_token=${getSaltedToken(k, tokenUuid, token)}`} style={{
46                             height: 0,
47                             width: 0,
48                             visibility: "hidden"
49                         }}
50                         />;
51                     })}
52             </div>;
53         }
54     });