mirror of
https://github.com/stalwartlabs/webui.git
synced 2026-12-06 16:04:38 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f835f4fd62 | ||
|
|
0697f8a0f4 | ||
|
|
e5a3b29125 | ||
|
|
d87912c39b |
No files matched your search
@@ -2,6 +2,34 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [2.0.3] - 2026-10-29
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
- Logging out no longer revokes the OAuth tokens.
|
||||
|
||||
### Fixed
|
||||
- OAuth sign-in sends the RFC 8707 `resource` parameter in the authorization request, the code exchange and token refreshes, so external identity providers that require an audience or scopes issue tokens the server accepts.
|
||||
|
||||
## [2.0.2] - 2026-10-28
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
- Object pickers in forms are now scoped to the tenant of the record being edited: for objects that belong to a tenant (`memberTenantId`), only options from the same tenant are offered.
|
||||
|
||||
### Fixed
|
||||
|
||||
## [2.0.1] - 2026-10-27
|
||||
|
||||
### Added
|
||||
|
||||
### Changed
|
||||
|
||||
### Fixed
|
||||
- Actions page hidden on Stalwart 1.0: create-only objects such as `x:Action` are now shown to accounts holding their Create permission (#27).
|
||||
|
||||
## [2.0.0] - 2026-10-26
|
||||
|
||||
### Added
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "stalwart-webui",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "stalwart-webui",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.3",
|
||||
"dependencies": {
|
||||
"@daypicker/react": "^10.0.2",
|
||||
"@noble/hashes": "^2.4.0",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "stalwart-webui",
|
||||
"private": true,
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.3",
|
||||
"stalwart": {
|
||||
"minServerVersion": "1.0.0"
|
||||
},
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Button } from '@/components/ui/button';
|
||||
import { ConfirmDialog } from '@/components/common/ConfirmDialog';
|
||||
import { useCanAccess } from '@/hooks/usePermissions';
|
||||
import { coerceLabel } from '@/lib/objectOptions';
|
||||
import { TENANT_PROPERTY } from '@/lib/schemaResolver';
|
||||
import { CreatedValuesDialog } from '@/components/forms/CreatedValuesDialog';
|
||||
import { FormProvider } from '@/components/forms/FormProvider';
|
||||
import { FormSections } from '@/components/forms/FormSections';
|
||||
@@ -108,6 +109,7 @@ export function DynamicForm({ viewName, objectId }: DynamicFormProps) {
|
||||
t('form.item', 'item')
|
||||
).toLowerCase();
|
||||
const sch = resolved.resolvedSchema;
|
||||
const tenantValue = state.data[TENANT_PROPERTY];
|
||||
|
||||
return (
|
||||
<div className="mx-auto max-w-4xl space-y-6">
|
||||
@@ -125,6 +127,7 @@ export function DynamicForm({ viewName, objectId }: DynamicFormProps) {
|
||||
readOnly={readOnly}
|
||||
recordLabel={model.recordLabel}
|
||||
baseline={state.original}
|
||||
tenantId={typeof tenantValue === 'string' ? tenantValue : null}
|
||||
>
|
||||
<FormSections
|
||||
sections={model.sections}
|
||||
|
||||
@@ -23,6 +23,7 @@ interface FormProviderProps {
|
||||
hideEnterprise?: boolean;
|
||||
recordLabel?: string;
|
||||
baseline?: unknown;
|
||||
tenantId?: string | null;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ export function FormProvider({
|
||||
hideEnterprise = false,
|
||||
recordLabel = '',
|
||||
baseline = null,
|
||||
tenantId = null,
|
||||
children,
|
||||
}: FormProviderProps) {
|
||||
const isCommunity = useIsCommunity();
|
||||
@@ -46,6 +48,7 @@ export function FormProvider({
|
||||
idPrefix,
|
||||
recordLabel,
|
||||
baseline,
|
||||
tenantId,
|
||||
};
|
||||
const scope: FieldScope = { path: [], readOnly };
|
||||
return (
|
||||
|
||||
@@ -18,6 +18,7 @@ export interface FormContextValue {
|
||||
idPrefix: string;
|
||||
recordLabel: string;
|
||||
baseline: unknown;
|
||||
tenantId: string | null;
|
||||
}
|
||||
|
||||
export interface FieldScope {
|
||||
|
||||
@@ -235,8 +235,8 @@ function MapKeyObjectIdInput({
|
||||
onChange: (v: string) => void;
|
||||
existingKeys: Record<string, unknown>;
|
||||
}) {
|
||||
const { schema } = useFormContext();
|
||||
const list = useObjectOptions(objectName, schema);
|
||||
const { schema, tenantId } = useFormContext();
|
||||
const list = useObjectOptions(objectName, schema, tenantId);
|
||||
const noPermissionMessage = useNoPermissionMessage(schema, objectName);
|
||||
return (
|
||||
<div className="flex flex-1 items-center gap-2">
|
||||
|
||||
@@ -47,9 +47,9 @@ export function ObjectIdWidget({
|
||||
control,
|
||||
}: WidgetProps<FieldTypeObjectId>) {
|
||||
const { t } = useTranslation();
|
||||
const { schema } = useFormContext();
|
||||
const { schema, tenantId } = useFormContext();
|
||||
const id = typeof value === 'string' ? value : '';
|
||||
const list = useObjectOptions(type.objectName, schema);
|
||||
const list = useObjectOptions(type.objectName, schema, tenantId);
|
||||
const noPermissionMessage = useNoPermissionMessage(schema, type.objectName);
|
||||
|
||||
return (
|
||||
@@ -99,8 +99,8 @@ export function ObjectIdMultiSelect({
|
||||
control,
|
||||
}: ObjectIdMultiSelectProps) {
|
||||
const { t } = useTranslation();
|
||||
const { schema } = useFormContext();
|
||||
const list = useObjectOptions(objectName, schema);
|
||||
const { schema, tenantId } = useFormContext();
|
||||
const list = useObjectOptions(objectName, schema, tenantId);
|
||||
const noPermissionMessage = useNoPermissionMessage(schema, objectName);
|
||||
const available = list.options.filter((o) => !items.includes(o.id));
|
||||
const atMinimum = minItems != null && items.length <= minItems;
|
||||
|
||||
@@ -26,7 +26,7 @@ import { EnterpriseUpsell } from '@/components/common/EnterpriseUpsell';
|
||||
import { DynamicIcon } from '@/components/common/DynamicIcon';
|
||||
import { useUIStore } from '@/stores/uiStore';
|
||||
import { useAuthStore } from '@/stores/authStore';
|
||||
import { buildEndSessionUrl, getPostLogoutRedirectUri, revokeSessionTokens } from '@/services/auth/oauth';
|
||||
import { buildEndSessionUrl, getPostLogoutRedirectUri } from '@/services/auth/oauth';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useIsCommunity } from '@/hooks/usePermissions';
|
||||
import { SIDEBAR_ID } from './sidebarContext';
|
||||
@@ -186,7 +186,6 @@ export function TopBar() {
|
||||
const endSessionUrl = endSessionEndpoint
|
||||
? buildEndSessionUrl(endSessionEndpoint, getPostLogoutRedirectUri())
|
||||
: null;
|
||||
if (endSessionUrl) revokeSessionTokens();
|
||||
logout();
|
||||
if (endSessionUrl) {
|
||||
window.location.href = endSessionUrl;
|
||||
|
||||
+2
-1
@@ -19,7 +19,8 @@ export const jmapKeys = {
|
||||
lists: (objectName: string) => ['jmap', objectName, 'list'] as const,
|
||||
list: (objectName: string, params: ListPageParams) => ['jmap', objectName, 'list', params] as const,
|
||||
allOptions: (objectName: string) => ['jmap', objectName, 'options'] as const,
|
||||
options: (objectName: string, viewName: string) => ['jmap', objectName, 'options', viewName] as const,
|
||||
options: (objectName: string, viewName: string, tenantId: string | null = null) =>
|
||||
['jmap', objectName, 'options', viewName, tenantId] as const,
|
||||
displayNames: (objectName: string) => ['jmap', objectName, 'displayName'] as const,
|
||||
displayName: (objectName: string, displayProperty: string, id: string) =>
|
||||
['jmap', objectName, 'displayName', displayProperty, id] as const,
|
||||
|
||||
@@ -9,7 +9,7 @@ import { queryOptions, useQuery, useQueryClient, type QueryClient } from '@tanst
|
||||
import { jmapKeys } from '@/data/keys';
|
||||
import { loadDisplayName } from '@/data/displayNames';
|
||||
import { coerceLabel } from '@/lib/objectOptions';
|
||||
import { getDisplayProperty, resolveList, resolveObject } from '@/lib/schemaResolver';
|
||||
import { getDisplayProperty, isTenantScoped, resolveList, resolveObject, TENANT_PROPERTY } from '@/lib/schemaResolver';
|
||||
import { jmapQueryAllAndGet } from '@/services/jmap/client';
|
||||
import type { Schema } from '@/types/schema';
|
||||
|
||||
@@ -48,14 +48,20 @@ export function displayNameQuery(schema: Schema, viewOrObjectName: string, id: s
|
||||
});
|
||||
}
|
||||
|
||||
export function objectOptionsQuery(schema: Schema, viewOrObjectName: string) {
|
||||
export function objectOptionsQuery(schema: Schema, viewOrObjectName: string, tenantId: string | null = null) {
|
||||
const objectName = parentObjectName(schema, viewOrObjectName);
|
||||
const displayProperty = getDisplayProperty(schema, viewOrObjectName);
|
||||
const filtersStatic = resolveList(schema, viewOrObjectName, objectName)?.filtersStatic;
|
||||
const filter = filtersStatic && Object.keys(filtersStatic).length > 0 ? filtersStatic : undefined;
|
||||
const scopedTenantId = tenantId !== null && isTenantScoped(schema, viewOrObjectName) ? tenantId : null;
|
||||
return queryOptions({
|
||||
queryKey: jmapKeys.options(objectName, viewOrObjectName),
|
||||
queryKey: jmapKeys.options(objectName, viewOrObjectName, scopedTenantId),
|
||||
queryFn: async ({ signal }): Promise<ObjectOption[]> => {
|
||||
const filtersStatic = resolveList(schema, viewOrObjectName, objectName)?.filtersStatic;
|
||||
const filter =
|
||||
scopedTenantId !== null
|
||||
? { ...filtersStatic, [TENANT_PROPERTY]: scopedTenantId }
|
||||
: filtersStatic && Object.keys(filtersStatic).length > 0
|
||||
? filtersStatic
|
||||
: undefined;
|
||||
const { list } = await jmapQueryAllAndGet(objectName, { filter }, ['id', displayProperty], { signal });
|
||||
const options: ObjectOption[] = [];
|
||||
for (const item of list) {
|
||||
@@ -69,10 +75,10 @@ export function objectOptionsQuery(schema: Schema, viewOrObjectName: string) {
|
||||
|
||||
const EMPTY_OPTIONS: ObjectOption[] = [];
|
||||
|
||||
export function useObjectOptions(viewOrObjectName: string, schema: Schema) {
|
||||
export function useObjectOptions(viewOrObjectName: string, schema: Schema, tenantId: string | null = null) {
|
||||
const [requested, setRequested] = useState(false);
|
||||
const query = useQuery({
|
||||
...objectOptionsQuery(schema, viewOrObjectName),
|
||||
...objectOptionsQuery(schema, viewOrObjectName, tenantId),
|
||||
enabled: requested,
|
||||
});
|
||||
const { isError, refetch } = query;
|
||||
|
||||
@@ -9,6 +9,7 @@ import { useNavigate } from 'react-router-dom';
|
||||
import { List, Plus, Settings } from 'lucide-react';
|
||||
import { useSchemaStore, type SearchIndexEntry } from '@/stores/schemaStore';
|
||||
import { usePermissionCheckers } from '@/hooks/usePermissions';
|
||||
import { isCreateOnly } from '@/lib/permissions';
|
||||
import { resolveObject } from '@/lib/schemaResolver';
|
||||
import type { Schema } from '@/types/schema';
|
||||
|
||||
@@ -82,7 +83,10 @@ export function useGlobalSearch(onAfterSelect?: () => void) {
|
||||
}
|
||||
const resolved = resolveObject(schema, entry.viewName);
|
||||
if (!resolved) return false;
|
||||
return hasObjectPermission(resolved.permissionPrefix, 'Get');
|
||||
return hasObjectPermission(
|
||||
resolved.permissionPrefix,
|
||||
isCreateOnly(schema, resolved.permissionPrefix) ? 'Create' : 'Get',
|
||||
);
|
||||
});
|
||||
|
||||
filtered.sort((a, b) => TYPE_ORDER[a.type] - TYPE_ORDER[b.type]);
|
||||
|
||||
+4
-2
@@ -6,7 +6,7 @@
|
||||
|
||||
import type { Layout, LayoutSubItem, Schema } from '@/types/schema';
|
||||
import { resolveObject } from '@/lib/schemaResolver';
|
||||
import { isCommunityEdition } from '@/lib/permissions';
|
||||
import { isCommunityEdition, isCreateOnly } from '@/lib/permissions';
|
||||
|
||||
export type CanGet = (permissionPrefix: string) => boolean;
|
||||
export type HasPermission = (permission: string) => boolean;
|
||||
@@ -65,7 +65,9 @@ export function isLinkVisible(schema: Schema, viewName: string, canGet: CanGet,
|
||||
const special = checkSpecialLink(schema, viewName, hasPerm, canGet);
|
||||
if (special !== null) return special.visible;
|
||||
const resolved = resolveObject(schema, viewName);
|
||||
return resolved !== null && canGet(resolved.permissionPrefix);
|
||||
if (resolved === null) return false;
|
||||
if (isCreateOnly(schema, resolved.permissionPrefix)) return hasPerm?.(`${resolved.permissionPrefix}Create`) ?? false;
|
||||
return canGet(resolved.permissionPrefix);
|
||||
}
|
||||
|
||||
export function isLinkEnterprise(schema: Schema, viewName: string): boolean {
|
||||
|
||||
@@ -30,6 +30,22 @@ export function createPermissionCheckers(permissions: readonly string[]): Permis
|
||||
return checkers;
|
||||
}
|
||||
|
||||
const definedPermissionsCache = new WeakMap<Schema, ReadonlySet<string>>();
|
||||
|
||||
function definedPermissions(schema: Schema): ReadonlySet<string> {
|
||||
let defined = definedPermissionsCache.get(schema);
|
||||
if (!defined) {
|
||||
defined = new Set((schema.enums['Permission'] ?? []).map((v) => v.name));
|
||||
definedPermissionsCache.set(schema, defined);
|
||||
}
|
||||
return defined;
|
||||
}
|
||||
|
||||
export function isCreateOnly(schema: Schema, permissionPrefix: string): boolean {
|
||||
const defined = definedPermissions(schema);
|
||||
return defined.has(`${permissionPrefix}Create`) && !defined.has(`${permissionPrefix}Get`);
|
||||
}
|
||||
|
||||
export function canAccessView(
|
||||
schema: Schema | null | undefined,
|
||||
viewName: string,
|
||||
|
||||
@@ -78,6 +78,23 @@ export function resolveSchema(schema: Schema, objectName: string): ResolvedSchem
|
||||
};
|
||||
}
|
||||
|
||||
export const TENANT_PROPERTY = 'memberTenantId';
|
||||
|
||||
function hasTenantProperty(schema: Schema, schemaName: string | undefined): boolean {
|
||||
if (schemaName === undefined) return false;
|
||||
const fields = schema.fields[schemaName];
|
||||
return fields !== undefined && Object.hasOwn(fields.properties, TENANT_PROPERTY);
|
||||
}
|
||||
|
||||
export function isTenantScoped(schema: Schema, viewOrObjectName: string): boolean {
|
||||
const entry = schema.objects[viewOrObjectName];
|
||||
const objectName = entry?.type === 'view' ? entry.objectName : viewOrObjectName;
|
||||
const schemaEntry = schema.schemas[objectName];
|
||||
if (!schemaEntry) return false;
|
||||
if (schemaEntry.type === 'single') return hasTenantProperty(schema, schemaEntry.schemaName);
|
||||
return schemaEntry.variants.some((v) => hasTenantProperty(schema, v.schemaName));
|
||||
}
|
||||
|
||||
export function resolveList(schema: Schema, viewName: string, objectName: string): List | null {
|
||||
return schema.lists[viewName] ?? schema.lists[objectName] ?? null;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export default function OAuthCallback() {
|
||||
throw new Error(t('oauth.missingParams', 'Missing authorization code or state parameter'));
|
||||
}
|
||||
|
||||
const { codeVerifier, tokenEndpoint, state, returnUrl, endSessionEndpoint, clientId, revocationEndpoint } =
|
||||
const { codeVerifier, tokenEndpoint, state, returnUrl, endSessionEndpoint, clientId, resource } =
|
||||
getStoredOAuthData();
|
||||
|
||||
if (!state || state !== stateParam) {
|
||||
@@ -64,7 +64,14 @@ export default function OAuthCallback() {
|
||||
}
|
||||
|
||||
const redirectUri = getOAuthRedirectUri();
|
||||
const tokenResponse = await exchangeCodeOnce(code, codeVerifier, tokenEndpoint, redirectUri, clientId);
|
||||
const tokenResponse = await exchangeCodeOnce(
|
||||
code,
|
||||
codeVerifier,
|
||||
tokenEndpoint,
|
||||
redirectUri,
|
||||
clientId,
|
||||
resource,
|
||||
);
|
||||
if (cancelled) return;
|
||||
|
||||
useAuthStore
|
||||
@@ -76,7 +83,7 @@ export default function OAuthCallback() {
|
||||
tokenEndpoint,
|
||||
endSessionEndpoint,
|
||||
clientId,
|
||||
revocationEndpoint,
|
||||
resource,
|
||||
);
|
||||
|
||||
clearStoredOAuthData();
|
||||
|
||||
+11
-6
@@ -25,21 +25,26 @@ function expireSession(): ApiError {
|
||||
}
|
||||
|
||||
async function performRefresh(): Promise<void> {
|
||||
const { refreshToken, tokenEndpoint, clientId } = useAuthStore.getState();
|
||||
const { refreshToken, tokenEndpoint, clientId, resource } = useAuthStore.getState();
|
||||
if (!refreshToken || !tokenEndpoint || !clientId) {
|
||||
throw expireSession();
|
||||
}
|
||||
|
||||
const body = new URLSearchParams({
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: refreshToken,
|
||||
client_id: clientId,
|
||||
});
|
||||
if (resource) {
|
||||
body.set('resource', resource);
|
||||
}
|
||||
|
||||
let response: Response;
|
||||
try {
|
||||
response = await fetch(tokenEndpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: new URLSearchParams({
|
||||
grant_type: 'refresh_token',
|
||||
refresh_token: refreshToken,
|
||||
client_id: clientId,
|
||||
}),
|
||||
body,
|
||||
});
|
||||
} catch (err) {
|
||||
throw new NetworkError(err);
|
||||
|
||||
+34
-26
@@ -18,10 +18,10 @@ export interface DiscoveryResponse {
|
||||
authorization_endpoint: string;
|
||||
token_endpoint: string;
|
||||
end_session_endpoint?: string;
|
||||
revocation_endpoint?: string;
|
||||
scopes_supported?: string[];
|
||||
client_id_metadata_document_supported?: boolean;
|
||||
stalwart_required_scopes?: string[];
|
||||
protected_resources?: string[];
|
||||
}
|
||||
|
||||
export function selectScopes(
|
||||
@@ -37,6 +37,23 @@ export function selectScopes(
|
||||
return discovery.scopes_supported?.includes('openid') ? 'openid' : '';
|
||||
}
|
||||
|
||||
export function selectResource(
|
||||
apiBaseUrl: string,
|
||||
discovery: Pick<DiscoveryResponse, 'protected_resources'>,
|
||||
): string | null {
|
||||
let origin: string;
|
||||
try {
|
||||
const url = new URL(apiBaseUrl);
|
||||
if (url.protocol !== 'https:') return null;
|
||||
origin = url.origin;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
const listed = discovery.protected_resources;
|
||||
if (Array.isArray(listed) && !listed.includes(origin)) return null;
|
||||
return origin;
|
||||
}
|
||||
|
||||
export async function discover(username: string): Promise<DiscoveryResponse> {
|
||||
const url = `${getApiBaseUrl()}/api/discover/${encodeURIComponent(username)}`;
|
||||
const response = await fetch(url);
|
||||
@@ -110,6 +127,7 @@ export async function exchangeCode(
|
||||
tokenEndpoint: string,
|
||||
redirectUri: string,
|
||||
clientId: string,
|
||||
resource: string | null,
|
||||
): Promise<TokenResponse> {
|
||||
const body = new URLSearchParams({
|
||||
grant_type: 'authorization_code',
|
||||
@@ -118,6 +136,9 @@ export async function exchangeCode(
|
||||
client_id: clientId,
|
||||
redirect_uri: redirectUri,
|
||||
});
|
||||
if (resource) {
|
||||
body.set('resource', resource);
|
||||
}
|
||||
|
||||
const response = await fetch(tokenEndpoint, {
|
||||
method: 'POST',
|
||||
@@ -144,7 +165,7 @@ function getRedirectUri(): string {
|
||||
|
||||
export async function startAuthFlow(username: string, returnUrl?: string | null): Promise<void> {
|
||||
const discovery = await discover(username);
|
||||
const { authorization_endpoint, token_endpoint, end_session_endpoint, revocation_endpoint } = discovery;
|
||||
const { authorization_endpoint, token_endpoint, end_session_endpoint } = discovery;
|
||||
|
||||
const clientId = resolveOAuthClientId(discovery.client_id_metadata_document_supported === true);
|
||||
if (!clientId) {
|
||||
@@ -175,16 +196,17 @@ export async function startAuthFlow(username: string, returnUrl?: string | null)
|
||||
sessionStorage.setItem(`${SESSION_PREFIX}state`, state);
|
||||
sessionStorage.setItem(`${SESSION_PREFIX}return_url`, safeReturnUrl);
|
||||
sessionStorage.setItem(`${SESSION_PREFIX}client_id`, clientId);
|
||||
const resource = selectResource(getApiBaseUrl(), discovery);
|
||||
if (resource) {
|
||||
sessionStorage.setItem(`${SESSION_PREFIX}resource`, resource);
|
||||
} else {
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}resource`);
|
||||
}
|
||||
if (end_session_endpoint) {
|
||||
sessionStorage.setItem(`${SESSION_PREFIX}end_session_endpoint`, end_session_endpoint);
|
||||
} else {
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}end_session_endpoint`);
|
||||
}
|
||||
if (revocation_endpoint) {
|
||||
sessionStorage.setItem(`${SESSION_PREFIX}revocation_endpoint`, revocation_endpoint);
|
||||
} else {
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}revocation_endpoint`);
|
||||
}
|
||||
|
||||
const params = new URLSearchParams({
|
||||
response_type: 'code',
|
||||
@@ -201,6 +223,9 @@ export async function startAuthFlow(username: string, returnUrl?: string | null)
|
||||
if (scope) {
|
||||
params.set('scope', scope);
|
||||
}
|
||||
if (resource) {
|
||||
params.set('resource', resource);
|
||||
}
|
||||
|
||||
window.location.href = `${authorization_endpoint}?${params.toString()}`;
|
||||
}
|
||||
@@ -212,8 +237,8 @@ export function getStoredOAuthData() {
|
||||
state: sessionStorage.getItem(`${SESSION_PREFIX}state`),
|
||||
returnUrl: sessionStorage.getItem(`${SESSION_PREFIX}return_url`),
|
||||
endSessionEndpoint: sessionStorage.getItem(`${SESSION_PREFIX}end_session_endpoint`),
|
||||
revocationEndpoint: sessionStorage.getItem(`${SESSION_PREFIX}revocation_endpoint`),
|
||||
clientId: sessionStorage.getItem(`${SESSION_PREFIX}client_id`),
|
||||
resource: sessionStorage.getItem(`${SESSION_PREFIX}resource`),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -223,8 +248,8 @@ export function clearStoredOAuthData(): void {
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}state`);
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}return_url`);
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}end_session_endpoint`);
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}revocation_endpoint`);
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}client_id`);
|
||||
sessionStorage.removeItem(`${SESSION_PREFIX}resource`);
|
||||
}
|
||||
|
||||
export function getOAuthRedirectUri(): string {
|
||||
@@ -246,20 +271,3 @@ export function buildEndSessionUrl(endSessionEndpoint: string, postLogoutRedirec
|
||||
const sep = endSessionEndpoint.includes('?') ? '&' : '?';
|
||||
return `${endSessionEndpoint}${sep}${params.toString()}`;
|
||||
}
|
||||
|
||||
export function revokeSessionTokens(): void {
|
||||
const { revocationEndpoint, clientId, refreshToken, accessToken } = useAuthStore.getState();
|
||||
const token = refreshToken || accessToken;
|
||||
if (!revocationEndpoint || !clientId || !token) return;
|
||||
const body = new URLSearchParams({
|
||||
token,
|
||||
token_type_hint: refreshToken ? 'refresh_token' : 'access_token',
|
||||
client_id: clientId,
|
||||
});
|
||||
fetch(revocationEndpoint, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body,
|
||||
keepalive: true,
|
||||
}).catch(() => undefined);
|
||||
}
|
||||
@@ -19,8 +19,8 @@ interface AuthState {
|
||||
tokenLifetime: number | null;
|
||||
tokenEndpoint: string | null;
|
||||
endSessionEndpoint: string | null;
|
||||
revocationEndpoint: string | null;
|
||||
clientId: string | null;
|
||||
resource: string | null;
|
||||
accounts: Record<string, AccountInfo>;
|
||||
primaryAccountId: string | null;
|
||||
activeAccountId: string | null;
|
||||
@@ -36,7 +36,7 @@ interface AuthState {
|
||||
tokenEndpoint: string,
|
||||
endSessionEndpoint?: string | null,
|
||||
clientId?: string | null,
|
||||
revocationEndpoint?: string | null,
|
||||
resource?: string | null,
|
||||
) => void;
|
||||
setSession: (
|
||||
accounts: Record<string, AccountInfo>,
|
||||
@@ -63,8 +63,8 @@ export const useAuthStore = create<AuthState>()(
|
||||
tokenLifetime: null,
|
||||
tokenEndpoint: null,
|
||||
endSessionEndpoint: null,
|
||||
revocationEndpoint: null,
|
||||
clientId: null,
|
||||
resource: null,
|
||||
accounts: {},
|
||||
primaryAccountId: null,
|
||||
activeAccountId: null,
|
||||
@@ -73,7 +73,7 @@ export const useAuthStore = create<AuthState>()(
|
||||
maxObjectsInSet: 500,
|
||||
sessionExpired: false,
|
||||
|
||||
setTokens: (access, refresh, expiresIn, tokenEndpoint, endSessionEndpoint, clientId, revocationEndpoint) => {
|
||||
setTokens: (access, refresh, expiresIn, tokenEndpoint, endSessionEndpoint, clientId, resource) => {
|
||||
const lifetime = Number.isFinite(expiresIn) && expiresIn > 0 ? expiresIn * 1000 : null;
|
||||
set({
|
||||
accessToken: access,
|
||||
@@ -83,7 +83,7 @@ export const useAuthStore = create<AuthState>()(
|
||||
tokenEndpoint,
|
||||
endSessionEndpoint: endSessionEndpoint === undefined ? get().endSessionEndpoint : endSessionEndpoint,
|
||||
clientId: clientId === undefined ? get().clientId : clientId,
|
||||
revocationEndpoint: revocationEndpoint === undefined ? get().revocationEndpoint : revocationEndpoint,
|
||||
resource: resource === undefined ? get().resource : resource,
|
||||
sessionExpired: false,
|
||||
});
|
||||
},
|
||||
@@ -115,8 +115,8 @@ export const useAuthStore = create<AuthState>()(
|
||||
tokenLifetime: null,
|
||||
tokenEndpoint: null,
|
||||
endSessionEndpoint: null,
|
||||
revocationEndpoint: null,
|
||||
clientId: null,
|
||||
resource: null,
|
||||
accounts: {},
|
||||
primaryAccountId: null,
|
||||
activeAccountId: null,
|
||||
@@ -167,8 +167,8 @@ export const useAuthStore = create<AuthState>()(
|
||||
tokenLifetime: state.tokenLifetime,
|
||||
tokenEndpoint: state.tokenEndpoint,
|
||||
endSessionEndpoint: state.endSessionEndpoint,
|
||||
revocationEndpoint: state.revocationEndpoint,
|
||||
clientId: state.clientId,
|
||||
resource: state.resource,
|
||||
activeAccountId: state.activeAccountId,
|
||||
}) as AuthState,
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user