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

Auto refresh token #6

Open
kbumsik opened this issue Feb 27, 2024 · 2 comments
Open

Auto refresh token #6

kbumsik opened this issue Feb 27, 2024 · 2 comments

Comments

@kbumsik
Copy link

kbumsik commented Feb 27, 2024

Hi,

Thank you for making a proper org feature in Keycloak!

We have been using keycloak-org for weeks with this Python client.

I noticed that python-keycloak package automatically refresh token when the token is expired, but this package does not.

Because of this, every time I make a request I have to refresh token (when expired) and create phasetwo.Configuration and phasetwo.ApiClient

keycloak_admin = KeycloakAdmin(server_url="https://my-keycloak-host/auth/",
                               username='admin',
                               password='password',
                               realm_name=realm,
                               client_id='admin-cli',
                               verify=True)

# Before making a request
if (keycloak_admin.connection.expires_at is None) or (datetime.now() >= keycloak_admin.connection.expires_at):
            keycloak_admin.connection.refresh_token()

configuration = phasetwo.Configuration(
    host = "https://app.phasetwo.io/auth/realms"
    access_token = keycloak_admin.token()
)

client = phasetwo.ApiClient(configuration)

Devs won't notice this until they come across this issue.

@xgp
Copy link
Member

xgp commented Feb 27, 2024

Good catch. I wasn't sure if calling the token() method automatically got a fresh token. Would you mind doing the PR?

@kbumsik
Copy link
Author

kbumsik commented Feb 28, 2024

Maybe I will think about proposing a PR after my current dev sprint at work ends 😝

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants