From a7fda8bd6b70e7b943dd219651ee57cf8fb37da9 Mon Sep 17 00:00:00 2001 From: Maurus Decimus <11444311+mdecimus@users.noreply.github.com> Date: Mon, 25 May 2026 13:58:38 +0200 Subject: [PATCH] Default scopes omit `offline_access` (fixes #10) --- CHANGELOG.md | 10 ++++++++++ package.json | 2 +- src/components/layout/ProtectedRoute.tsx | 4 ++-- src/services/api.ts | 16 +++++++++++----- src/services/auth/oauth.ts | 5 ++--- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 14e1df3..f2d7b79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.5] - 2026-05-XX + +### Added + +### Changed + +### Fixed +- Redirect to `/login` when there is no refresh token. +- Default scopes omit `offline_access`. + ## [1.0.4] - 2026-05-11 ### Added diff --git a/package.json b/package.json index 91f334f..c7334b5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "stalwart-webui", "private": true, - "version": "1.0.4", + "version": "1.0.5", "description": "Stalwart WebUI", "type": "module", "scripts": { diff --git a/src/components/layout/ProtectedRoute.tsx b/src/components/layout/ProtectedRoute.tsx index 219e63f..7b1e710 100644 --- a/src/components/layout/ProtectedRoute.tsx +++ b/src/components/layout/ProtectedRoute.tsx @@ -8,10 +8,10 @@ import { Navigate, useLocation } from 'react-router-dom'; import { useAuthStore } from '@/stores/authStore'; export function ProtectedRoute({ children }: { children: React.ReactNode }) { - const accessToken = useAuthStore((s) => s.accessToken); + const authenticated = useAuthStore((s) => s.isAuthenticated()); const bypassToken = import.meta.env.VITE_ACCESS_TOKEN; const location = useLocation(); - if (!accessToken && !bypassToken) { + if (!authenticated && !bypassToken) { const originalPath = location.pathname + location.search; return ; } diff --git a/src/services/api.ts b/src/services/api.ts index ae2c3df..b8d6745 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -107,11 +107,17 @@ export async function apiFetch(path: string, options?: RequestInit): Promise { - const { authorization_endpoint, token_endpoint, end_session_endpoint, scopes_supported } = - await discover(username); + const { authorization_endpoint, token_endpoint, end_session_endpoint, scopes_supported } = await discover(username); const codeVerifier = generateCodeVerifier(); const { challenge: codeChallenge, method: codeChallengeMethod } = await generateCodeChallenge(codeVerifier); @@ -167,7 +166,7 @@ export async function startAuthFlow(username: string, returnUrl?: string | null) if (SCOPES && SCOPES.length > 0) { scope = SCOPES; } else if (scopes_supported?.includes('openid')) { - scope = ['openid', 'email', 'profile'].filter((s) => scopes_supported.includes(s)).join(' '); + scope = ['openid', 'email', 'profile', 'offline_access'].filter((s) => scopes_supported.includes(s)).join(' '); } else { scope = ''; }