Files
cinny/src/app/pages/auth/oidc/oidcConfig.ts
T

37 lines
1.5 KiB
TypeScript
Raw Normal View History

import type { OAuthRegistrationRequest } from 'matrix-js-sdk';
import { OIDC_CALLBACK_PATH } from '../../paths';
import { getOriginBaseUrl, withOriginBaseUrl } from '../../pathUtils';
const LotusLogo = withOriginBaseUrl(getOriginBaseUrl(), '/public/res/lotus-logo.png');
/**
* Absolute URL the OIDC provider redirects back to after authorization.
*
* It MUST be a real (non-hash) path on our origin: OAuth redirect_uris cannot
* contain a fragment, and with hashRouter the app's routes live after `#`. We
* therefore always build it against the plain origin base — `getOriginBaseUrl()`
* with NO hashRouter arg returns `${origin}${BASE_URL}` (no `#`) — and App.tsx
* short-circuits this path before the router mounts.
*/
export const getOidcCallbackUrl = (): string =>
withOriginBaseUrl(getOriginBaseUrl(), OIDC_CALLBACK_PATH);
/**
* Client metadata sent during dynamic client registration.
*
* The SDK drops any URI that doesn't share `client_uri` as a common base, so
* every URI here lives under our origin base.
*/
export const getOidcClientMetadata = (): OAuthRegistrationRequest => {
// `${origin}${BASE_URL}` (with trailing slash) — the common base for all URIs.
const clientUri = getOriginBaseUrl();
return {
client_name: 'Lotus Chat',
client_uri: clientUri,
logo_uri: new URL(LotusLogo, window.location.origin).href,
application_type: 'web',
tos_uri: clientUri,
policy_uri: clientUri,
redirect_uris: [getOidcCallbackUrl()],
};
};