16812: Handoff token using query param
[arvados-workbench2.git] / src / views-components / context-menu / actions / helpers.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export const sanitizeToken = (href: string, tokenAsQueryParam: boolean = true): string => {
6     const [prefix, suffix] = href.split('/t=');
7     const [token, ...rest] = suffix.split('/');
8
9     const sep = href.indexOf("?") > -1 ? "&" : "?";
10
11     return `${[prefix, ...rest].join('/')}${tokenAsQueryParam ? `${sep}api_token=${token}` : ''}`;
12 };
13
14 export const getClipboardUrl = (href: string): string => {
15     const { origin } = window.location;
16     const url = sanitizeToken(href, false);
17
18     return `${origin}?redirectTo=${url}`;
19 };