17782: Removes the last linter warnings.
[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 React from 'react';
6 import { connect } from 'react-redux';
7 import { RootState } from 'store/store';
8 import { User } from "models/user";
9 import { getSaltedToken } from 'store/auth/auth-action-session';
10 import { Config } from 'common/config';
11
12 export interface FedLoginProps {
13     user?: User;
14     apiToken?: string;
15     localCluster: string;
16     remoteHostsConfig: { [key: string]: Config };
17 }
18
19 const mapStateToProps = ({ auth }: RootState) => ({
20     user: auth.user,
21     apiToken: auth.apiToken,
22     remoteHostsConfig: auth.remoteHostsConfig,
23     localCluster: auth.localCluster,
24 });
25
26 export const FedLogin = connect(mapStateToProps)(
27     class extends React.Component<FedLoginProps> {
28         render() {
29             const { apiToken, user, localCluster, remoteHostsConfig } = this.props;
30             if (!apiToken || !user || !user.uuid.startsWith(localCluster)) {
31                 return <></>;
32             }
33             return <div id={"fedtoken-iframe-div"}>
34                 {Object.keys(remoteHostsConfig)
35                     .map((k) => {
36                         if (k === localCluster) {
37                             return null;
38                         }
39                         if (!remoteHostsConfig[k].workbench2Url) {
40                             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.`);
41                             return null;
42                         }
43                         const fedtoken = (remoteHostsConfig[k].loginCluster === localCluster)
44                             ? apiToken : getSaltedToken(k, apiToken);
45                         return <iframe key={k} title={k} src={`${remoteHostsConfig[k].workbench2Url}/fedtoken?api_token=${fedtoken}`} style={{
46                             height: 0,
47                             width: 0,
48                             visibility: "hidden"
49                         }}
50                         />;
51                     })}
52             </div>;
53         }
54     });