Refreshing authorization token in worker, something like a token supplier

Hi guys.

I’m testing the alpha version of the Python SDK and I have a question about how to handle token refresh in an authoring scenario when making a Worker Activity.

Use case:
I need to send an “authorization” header in the GRPC request, a bearer token for example, and I can refresh it (own logic) whenever I want without creating a new Worker Activity.
This same problem I have already solved successfully with a supplier token in the JAVA SDK (How to provide an Authorization Token in Java (JWT) | Temporal Documentation).

The problem:
Examining the Python SDK code and also the Core-SDK code, I know that there is support for sending “static_headers”, in the client configuration.

    client = await Client.connect(
        target_url=target_url,
        namespace=namespace,
        tls_config=tls_config,
        interceptors=[interceptor],
        static_headers={"authorization": "Bearer eyJra..."}
    )

    worker = Worker(
        client,
        task_queue=task_queue,
        activities={"say-hello-activity": say_hello_activity}
    )

That way, I am successfully authorizing the various GRPC connections to Temporal. However, unlike Java, I don’t know how to handle refreshing Tokens dynamically, without instantiating a new Worker.

Can you come up with any ideas?. My python skills are a bit inferior to the rest of the SDK languages so any advice is welcome. Is this use case a limitation of the actual Rust binding?, that is, if I used the Typescript sdk, I would have the same problem?

Thank you

1 Like

This is a current limitation with Core based SDKs.
The Python SDK worker uses a Rust Core client which only supports static headers at the moment.
I’ll open an issue to add support for dynamic headers.

Oki, I will keep an eye on the repos. Thanks for the effort.

2 Likes