I have a Nuxt3 Frontend and use Self Hosted Appwrite in the Backend. I created a FastAPI Backend with Celery to cut videos from the Appwrite Storage with FFmpeg.
Everything works but right now the FastAPI is a open door 😉 Is there a way to use the Session Cookie from Nuxt3 Client Side to validate the User Request against FastAPI? Didn't find any SDK function for Python Server Side to validation Cookie sessions.
Thanks a lot 🙂
Summary
User wants to use the session cookie from their Nuxt3 frontend to authenticate requests to a FastAPI backend. They are looking for a way to validate the cookie sessions on the server side, but haven't found any specific SDK functions for Python.
Solution: There doesn't seem to be a direct SDK function available. One suggestion is to manually validate the cookie by making a GET account API call with it. Additionally, using JSON Web Tokens (JWTs) and calling `getJWT()` from where the user is logged in might be an option.
Drake
Nov 5, 2023, 21:40
This is an Appwrite cookie?
WuGGu
Rank 2: Process
Nov 6, 2023, 14:58
yes
Drake
Nov 6, 2023, 21:04
you'd have to manually make the get account API call, then
WuGGu
Rank 2: Process
Nov 7, 2023, 13:17
I'm logged in in my VueJS application and want to trigger a REST API which does some stuff and to control access via Appwrite Auth. So my idea was to send the Appwrite cookie I have already with my API Call against the REST API.
Does this make sense?
ideclon
Rank 5: Hypervisor
Nov 7, 2023, 14:27
You should probably call getJWT from wherever you're logged in, and use that. I guess you could technically use the cookie, but then you'd only have client side access.
ideclon
Rank 5: Hypervisor
Nov 7, 2023, 14:27
I think
Drake
Nov 8, 2023, 00:13
You'd still only have client side access with a JWT 🧐
Drake
Nov 8, 2023, 00:14
Sure and to validate the cookie, you need to make an API call with it like a get account API call .
ideclon
Rank 5: Hypervisor
Nov 8, 2023, 00:25
Oh - I’ve never used the JWT flow, but I guess that makes sense. Yeah, so you’d need to use the cookie/JWT to call getAccount() to check that it’s valid, then go ahead with an API key
ideclon
Rank 5: Hypervisor
Nov 8, 2023, 00:26
Thoughts on a server side validateJWT(), or something? Or the ability to assume a user identity, whilst still having access to server-side functions
Drake
Nov 8, 2023, 00:29
Server side you would call setJwt() to take actions on behalf of the user like calling account.get() to validate the JWT.
ideclon
Rank 5: Hypervisor
Nov 8, 2023, 00:30
I was thinking of a one-step function you could just use to get the validity of a JWT and user details, instead of assuming the identity and then checking you have a valid session
Drake
Nov 8, 2023, 00:33
One step makes it less flexible. The setJWT pattern matches setKey
ideclon
Rank 5: Hypervisor
Nov 8, 2023, 00:42
I’m not suggesting replacing setJWT() - I’m suggesting a new function that would just validate a JWT and get data about that JWT.