Authentication with Keycloak and how to store access token to reuse it later? #3310
Unanswered
albertalexandrov
asked this question in
Q&A
Replies: 1 comment
-
Hey! Example: import typing
from httpx import Auth, Request, Response, AsyncClient
import asyncio
count = 0
class IntgrPltfrmAuth(Auth):
def __init__(self):
global count
count += 1
async def async_auth_flow(self, request: Request) -> typing.AsyncGenerator[Request, Response]:
yield request
client = AsyncClient(auth=IntgrPltfrmAuth())
async def main():
await client.get("https://httpbin.org/headers")
await client.get("https://httpbin.org/headers")
assert count == 1
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I have 2 services and KeyCloak. Service A should get access token from KeyCloak to make requests to service B.
For that I've written Auth subclass to authenticate through KeyCloak:
As you could notice to reuse access token and public key I store them globally. What is common practice in those cases? Store in Redis or something like this? I don't like very much storing in global.
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions