1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
12 export interface FedLoginProps {
16 remoteHostsConfig: { [key: string]: Config };
19 const mapStateToProps = ({ auth }: RootState) => ({
21 apiToken: auth.apiToken,
22 remoteHostsConfig: auth.remoteHostsConfig,
23 localCluster: auth.localCluster,
26 export const FedLogin = connect(mapStateToProps)(
27 class extends React.Component<FedLoginProps> {
29 const { apiToken, user, localCluster, remoteHostsConfig } = this.props;
30 if (!apiToken || !user || !user.uuid.startsWith(localCluster)) {
33 return <div id={"fedtoken-iframe-div"}>
34 {Object.keys(remoteHostsConfig)
36 if (k === localCluster) {
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.`);
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={{