fix(auth): allow anonymous access to share-link endpoints (#1617)
The global Auth middleware allowlist (noAuthAPI) was missing the share-link routes, so an unauthenticated invitee opening /register?token= hit a 401 on /auth/invitations/lookup and the frontend bounced them to /login instead of showing the register page. Add both share-link endpoints to the allowlist and stop the request interceptor from treating their 401s as a session-expiry redirect. Refs: https://github.com/Tencent/WeKnora/issues/1617
This commit is contained in:
@@ -63,7 +63,12 @@ instance.interceptors.request.use(
|
|||||||
let isRefreshing = false;
|
let isRefreshing = false;
|
||||||
let failedQueue: Array<{ resolve: Function; reject: Function }> = [];
|
let failedQueue: Array<{ resolve: Function; reject: Function }> = [];
|
||||||
|
|
||||||
const PUBLIC_AUTH_PATHS = ['/auth/auto-setup', '/auth/login', '/auth/register', '/auth/oidc/'];
|
// Share-link endpoints (/auth/invitations/lookup, /auth/register-by-invite)
|
||||||
|
// are reachable by anonymous users opening an invite link. A 401 from these
|
||||||
|
// must surface to the page (e.g. expired token), not trigger the
|
||||||
|
// refresh-then-redirect-to-login flow (issue #1617). '/auth/register' already
|
||||||
|
// covers '/auth/register-by-invite' via substring match.
|
||||||
|
const PUBLIC_AUTH_PATHS = ['/auth/auto-setup', '/auth/login', '/auth/register', '/auth/oidc/', '/auth/invitations/lookup'];
|
||||||
|
|
||||||
function isPublicAuthRequest(url?: string): boolean {
|
function isPublicAuthRequest(url?: string): boolean {
|
||||||
if (!url) return false;
|
if (!url) return false;
|
||||||
|
|||||||
@@ -20,15 +20,23 @@ import (
|
|||||||
|
|
||||||
// 无需认证的API列表
|
// 无需认证的API列表
|
||||||
var noAuthAPI = map[string][]string{
|
var noAuthAPI = map[string][]string{
|
||||||
"/health": {"GET"},
|
"/health": {"GET"},
|
||||||
"/api/v1/auth/register": {"POST"},
|
"/api/v1/auth/register": {"POST"},
|
||||||
"/api/v1/auth/login": {"POST"},
|
"/api/v1/auth/login": {"POST"},
|
||||||
"/api/v1/auth/auto-setup": {"POST"},
|
"/api/v1/auth/auto-setup": {"POST"},
|
||||||
"/api/v1/auth/config": {"GET"},
|
// Share-link surfaces accept a plaintext invite token from anonymous
|
||||||
"/api/v1/auth/oidc/config": {"GET"},
|
// callers (an invitee who hasn't registered yet). They are registered
|
||||||
"/api/v1/auth/oidc/url": {"GET"},
|
// as public routes in RegisterAuthRoutes and rate-limited by IP, so the
|
||||||
"/api/v1/auth/oidc/callback": {"GET"},
|
// global Auth middleware must let them through — otherwise opening a
|
||||||
"/api/v1/auth/refresh": {"POST"},
|
// share link while logged out 401s and the frontend bounces the user to
|
||||||
|
// /login instead of the register page (issue #1617).
|
||||||
|
"/api/v1/auth/invitations/lookup": {"POST"},
|
||||||
|
"/api/v1/auth/register-by-invite": {"POST"},
|
||||||
|
"/api/v1/auth/config": {"GET"},
|
||||||
|
"/api/v1/auth/oidc/config": {"GET"},
|
||||||
|
"/api/v1/auth/oidc/url": {"GET"},
|
||||||
|
"/api/v1/auth/oidc/callback": {"GET"},
|
||||||
|
"/api/v1/auth/refresh": {"POST"},
|
||||||
// IM platforms (Feishu, Slack, etc.) commonly issue a HEAD request
|
// IM platforms (Feishu, Slack, etc.) commonly issue a HEAD request
|
||||||
// before GET to validate Content-Type / Content-Length when rendering
|
// before GET to validate Content-Type / Content-Length when rendering
|
||||||
// image previews — both verbs must be allowed for image links to work.
|
// image previews — both verbs must be allowed for image links to work.
|
||||||
|
|||||||
Reference in New Issue
Block a user