Skip to content

Persistent "Token expired" error after JWT expires #3

@moritzploss-k

Description

@moritzploss-k

Hi and thanks for making this library!

We are exploring to use brod_oauth for SASL/OAUTHBEARER authentication towards Kafka. Our JWT tokens are valid for 30 minutes, and it works fine to connect to Kafka while the token is valid. However, after the token expires, we get errors like this, which are only resolved by an application restart:

exception error: {sasl_auth_error,<<"Token expired at: 1742309468000 (2025-03-18T14:51:08 UTC) (ErrId: 2791d48d)">>}

Looking at the code in brod_oauth, my understanding is that tokens are only used to establish a connection, but that connections may live longer than the corresponding token, and that tokens for a given connection don't get refreshed dynamically. Is that correct?

Any help would be much appreciated!

Our Config

Our brod config looks like this:

{brod, [
    {clients, [
        {client_name, [
            {endpoints, [{"${KAFKA_HOST}", ${KAFKA_PORT}}]},
            {ssl, true},
            {sasl, {callback, brod_oauth, #{token_callback => fun module:callback/1}}}
        ]}
    ]}
]}

And a call to module:callback/1 returns the following, where Token is a JWT access token:

{ok, #{token => Token}}

Subsequent calls to module:callback/1 return the same token as long as the token is not expired, and a new token after the token expires.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions