Back

Check Cookie in FastAPI Backend

  • 0
  • Self Hosted
  • Web
WuGGu
4 Nov, 2023, 08:55

Hi all,

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 πŸ™‚

TL;DR
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
5 Nov, 2023, 21:40

This is an Appwrite cookie?

WuGGu
6 Nov, 2023, 14:58

yes

Drake
6 Nov, 2023, 21:04

you'd have to manually make the get account API call, then

WuGGu
7 Nov, 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
7 Nov, 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
7 Nov, 2023, 14:27

I think

Drake
8 Nov, 2023, 00:13

You'd still only have client side access with a JWT 🧐

Drake
8 Nov, 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
8 Nov, 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
8 Nov, 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
8 Nov, 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
8 Nov, 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
8 Nov, 2023, 00:33

One step makes it less flexible. The setJWT pattern matches setKey

ideclon
8 Nov, 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.

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more