Skip to content

Authenticating API and frontend using Fief(Fastapi) #368

Answered by swanny69420
swanny69420 asked this question in Q&A
Discussion options

You must be logged in to vote

FIXED:
For those trying to recreate this method, here is what I did.
for every api endpoint you want to require auth, chuck this in the function declaration: user: FiefUserInfo = Depends(auth.authenticated())
Then, append your get_unauthorized_response function to include this handler, so it dosen't try and redirect API requests to the login page:
if request.url.path.startswith("/api"): raise HTTPException(status_code=HTTP_401_UNAUTHORIZED) (this only works if your API is behind the prefix /API.
From memory that is all that I did to make it work, but I might have done other things, I will keep you updated if i did.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@swanny69420
Comment options

@swanny69420
Comment options

Answer selected by swanny69420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants