Add API-aware authentication with auto-detection (needs execution flow fix)
✅ Working: - Auto-detects API requests from /api/ in URI - Optional :api keyword parameter for explicit control - Returns JSON for API requests, redirects for pages - Page redirects work perfectly (admin page redirects to login) - API detection logs show correct behavior ❌ Issue: - API endpoints still execute after require-authentication returns JSON - radiance:api-output doesn't stop execution like redirect does - Need proper Radiance mechanism to halt request processing Question for easilokx: What's the correct way to stop execution and return JSON from a helper function like require-authentication? We tried api-output but execution continues. How does redirect actually stop execution?
This commit is contained in:
parent
707e7aba96
commit
9ec7848b47
|
|
@ -148,12 +148,11 @@
|
||||||
(progn
|
(progn
|
||||||
(format t "Authentication failed - returning JSON 401~%")
|
(format t "Authentication failed - returning JSON 401~%")
|
||||||
(setf (radiance:header "Content-Type") "application/json")
|
(setf (radiance:header "Content-Type") "application/json")
|
||||||
(setf (radiance:response-data)
|
(radiance:api-output
|
||||||
(cl-json:encode-json-to-string
|
(cl-json:encode-json-to-string
|
||||||
`(("error" . "Authentication required")
|
`(("error" . "Authentication required")
|
||||||
("status" . 401)
|
("status" . 401)
|
||||||
("message" . "You must be logged in to access this resource"))))
|
("message" . "You must be logged in to access this resource")))))
|
||||||
(radiance:redirect (radiance:uri)))
|
|
||||||
;; Page request - redirect to login
|
;; Page request - redirect to login
|
||||||
(progn
|
(progn
|
||||||
(format t "Authentication failed - redirecting to login~%")
|
(format t "Authentication failed - redirecting to login~%")
|
||||||
|
|
@ -193,9 +192,8 @@
|
||||||
(progn
|
(progn
|
||||||
(format t "Role check failed - returning JSON 403~%")
|
(format t "Role check failed - returning JSON 403~%")
|
||||||
(setf (radiance:header "Content-Type") "application/json")
|
(setf (radiance:header "Content-Type") "application/json")
|
||||||
(error 'api-auth-error
|
(radiance:api-output
|
||||||
:status-code 403
|
(cl-json:encode-json-to-string
|
||||||
:json-response (cl-json:encode-json-to-string
|
|
||||||
`(("error" . "Authentication required")
|
`(("error" . "Authentication required")
|
||||||
("status" . 403)
|
("status" . 403)
|
||||||
("message" . ,(format nil "You must be logged in with ~a role to access this resource" role))))))
|
("message" . ,(format nil "You must be logged in with ~a role to access this resource" role))))))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue