doing auth with fastapi + idom #594
Replies: 6 comments 33 replies
-
There should definitely be a better way of adding authentication in IDOM. @Archmonger is using a similar strategy in a project based on django-idom. This works in Django IDOM for two reasons:
We can solve 1 in IDOM core with the upcoming from idom.server.fastapi import RequestContext
from idom import component, use_context
@component
def AuthenticatedView():
request = use_context(RequestContext)
# use some sort of auth token on the request For 2 though, I haven't really had time to figure out a good way of saving client-side state. It's certainly possible, the question is what the API should be:
Not having thought about this much, I'd lean towards the custom component solution, at least initially, since that wouldn't require any big changes. |
Beta Was this translation helpful? Give feedback.
-
thanks for this, sounds like what I need. Question, what will the RequestContext object contain?
…
On 14 Feb 2022, at 19:08, Ryan Morshead ***@***.***> wrote:
Presently, IDOM does not expose the request associated with the underlying websocket connection. Ultimately I intend to do this with contexts. A usage might look like:
from idom import component, use_context
from idom.server.fastapi import RequestContext
@component
def MyComponent():
request = use_context(RequestContext)
...
Unfortunately I've been bogged down with work and more pressing bug fixes and so I haven't managed to get contexts across the finish line.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you authored the thread.
|
Beta Was this translation helpful? Give feedback.
-
I have noticed |
Beta Was this translation helpful? Give feedback.
-
I was wondering if we could handle auth in a FastApi application and somehow pass the logged user information down to IDOM? |
Beta Was this translation helpful? Give feedback.
-
On fastapi, I have used middleware to get the request header https://github.com/tomwojcik/starlette-context |
Beta Was this translation helpful? Give feedback.
-
@acivitillo have you gotten a chance to try out 0.38.0-a1 and if so, would that release be sufficient for you to proceed with development while I'm on vacation? I'm thinking that for a 0.38.0 release I'd like to complete #721, #720, and maybe #653. |
Beta Was this translation helpful? Give feedback.
-
Completely experimental, never seen this before, but it works. The idea is to move auth to the FastAPI API layer and store the
access_token
in the idom state.Is it crazy though? I mean it's relatively simple to reason about in idom, but I wonder if this makes sense. I guess the user would have to login every time the websocket connection is lost.
Better ideas? It would probably be convenient for idom to store some state in a client cookie.
Beta Was this translation helpful? Give feedback.
All reactions