Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AsyncIO - Allow providing an initial aiohttp session to the auth0 client #317

Closed
ca-simone-chiorazzo opened this issue May 20, 2022 · 3 comments · Fixed by #443
Closed
Labels
feature request A feature has been asked for or suggested by the community

Comments

@ca-simone-chiorazzo
Copy link

Describe the problem you'd like to have solved

We've refactored our implementation of auth0 python in order to leverage the new asyncio support.
During the development, we've found difficult to provide an aiohttp HTTP client session to the auth0 SDK, making difficult to leverage a best practice like https://docs.aiohttp.org/en/stable/faq.html#how-do-i-manage-a-clientsession-within-a-web-server

Describe the ideal solution

Provide a way to inject a custom aiohttp client session that can be reused in a web server.

Alternatives and current work-arounds

for name in modules.keys():
            module = getattr(auth0_client, name)
            module._async_client.client.set_session(SingletonAuth0AiohttpClientSession.get_aiohttp_client_session())

where the SingletonAuth0AiohttpClientSession is a class that is managed by FastAPI application events that automatically closes the session on the application shutdown.

Additional information, if any

@ca-simone-chiorazzo ca-simone-chiorazzo added the feature request A feature has been asked for or suggested by the community label May 20, 2022
@adamjmcgrath
Copy link
Contributor

Hi @ca-simone-chiorazzo - thanks for raising this

You can share a session between individual services as follows:

  Users = asyncify(Users)
  Connections = asyncify(Connections)
  session = aiohttp.ClientSession()
  users = Users(domain, mgmt_api_token)
  connections = Connections(domain, mgmt_api_token)
  users.set_session(session)
  connections.set_session(session) 
  u = await auth0.users.all_async()
  c = await auth0.connections.all_async()
  session.close()

Is this what you were after?

@ca-simone-chiorazzo
Copy link
Author

@adamjmcgrath Nope, I was referring to passing the client session directly to the Auth0 client and not on individual services

@ca-simone-chiorazzo
Copy link
Author

ca-simone-chiorazzo commented Sep 16, 2022

@adamjmcgrath
It would be great to have something like:

session = aiohttp.ClientSession()
auth0_client = Auth0(domain='a-domain', token='a-token', http_session=session)

in order to be able to continue leverage the Auth0 object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants