clientMetadata

tcmts.registry.session.clientMetadata · #gmzx5zpu · term · runs in the browser

uses location

The OAuth client this page is: the loopback one on localhost, else the metadata document the registry serves. Either comes back to the registry's home, which finishes signing in and goes back to the page it started from.

import { href } from "#codebase/tcmts/react";
import { REGISTRY_SCOPE } from "#codebase/tcmts/registry/session";

export function clientMetadata(): { client_id: string; redirect_uri: string } {
  const local = location.hostname === "localhost" || location.hostname === "127.0.0.1";
  // (a loopback client must come back to 127.0.0.1, not localhost)
  const redirect = `${location.origin.replace("//localhost", "//127.0.0.1")}${href("/")}`;
  return local
    ? {
        client_id: `http://localhost?redirect_uri=${encodeURIComponent(redirect)}&scope=${encodeURIComponent(REGISTRY_SCOPE)}`,
        redirect_uri: redirect,
      }
    : { client_id: `${location.origin}${href("/api/oauth/client")}`, redirect_uri: redirect };
}

uses

used by