1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
13 export interface FedLoginProps {
17 remoteHostsConfig: { [key: string]: Config };
20 const mapStateToProps = ({ auth }: RootState) => ({
22 apiToken: auth.apiToken,
23 remoteHostsConfig: auth.remoteHostsConfig,
24 localCluster: auth.localCluster,
27 export const FedLogin = connect(mapStateToProps)(
28 class extends React.Component<FedLoginProps> {
30 const { apiToken, user, localCluster, remoteHostsConfig } = this.props;
31 if (!apiToken || !user || !user.uuid.startsWith(localCluster)) {
34 const [, tokenUuid, token] = apiToken.split("/");
35 return <div id={"fedtoken-iframe-div"}>
36 {Object.keys(remoteHostsConfig)
38 if (k === localCluster) {
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.`);
45 return <iframe key={k} src={`${remoteHostsConfig[k].workbench2Url}/fedtoken?api_token=${getSaltedToken(k, tokenUuid, token)}`} style={{