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

[BUG] TokenManager does not re-init expired sessions #530

Open
StenGruener opened this issue Nov 20, 2024 · 2 comments
Open

[BUG] TokenManager does not re-init expired sessions #530

StenGruener opened this issue Nov 20, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@StenGruener
Copy link
Contributor

StenGruener commented Nov 20, 2024

Describe the bug
TokenManager does not re-init expired sessions.

To Reproduce
0) Init basyx secured
Here is keycloak config

image

TokenManager t = new TokenManager("<endpoint>",  new PasswordCredentialAccessTokenProvider(new PasswordCredential("<user>", "<pass>"), new ClientCredential("<client-id>", "<client-secret>")));

get a token

t.getAccessToken();

Start getting tokens every max idle time, e.g., every 2 minutes

while(true){
t.getAccessToken();
Sleep(120);
}

wait until session timeouts, e.g., 10 hours

t.getAccessToken();

throws an error AccessTokenRetreivalException

As far as i see the only way ATM is to careate a new TokenManager with a new new.

Expected behavior
Eiter some less-generic Exception, better a pro-active token/session refresh.

BaSyx (please complete the following information):

  • BaSyx Version 2.0.0-Snapshot
  • BaSyx SDK Java
  • AAS Version DotAAS V3

Screenshots

Error occurred while retrieving access tokencom.nimbusds.oauth2.sdk.TokenErrorResponse@e78d962\n\tat org.eclipse.digitaltwin.basyx.client.internal.authorization.grant.PasswordCredentialAccessTokenProvider.getTokenResponse(PasswordCredentialAccessTokenProvider.java:112)\n\tat org.eclipse.digitaltwin.basyx.client.internal.authorization.grant.PasswordCredentialAccessTokenProvider.getAccessTokenResponse(PasswordCredentialAccessTokenProvider.java:99)\n\tat org.eclipse.digitaltwin.basyx.client.internal.authorization.TokenManager.getAccessToken(TokenManager.java:78)\n\tat org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi.addAuthorizationHeaderIfAuthIsEnabled(RegistryAndDiscoveryInterfaceApi.java:1250)\n\tat org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi.getAllAssetAdministrationShellDescriptorsRequestBuilder(RegistryAndDiscoveryInterfaceApi.java:463)\n\tat org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi.getAllAssetAdministrationShellDescriptorsWithHttpInfo(RegistryAndDiscoveryInterfaceApi.java:401)\n\tat org.eclipse.digitaltwin.basyx.aasregistry.client.api.RegistryAndDiscoveryInterfaceApi.getAllAssetAdministrationShellDescriptors(RegistryAndDiscoveryInterfaceApi.java:386)
@StenGruener StenGruener added the bug Something isn't working label Nov 20, 2024
@StenGruener StenGruener changed the title [BUG] [BUG] TokenManager does not re-init expired sessions Nov 20, 2024
@StenGruener
Copy link
Contributor Author

In TokenManager.java there are some hard-coded values:

refreshTokenExpiryTime = System.currentTimeMillis() + (30L * 24L * 60L * 60L * 1000L);

Where are those 30 hours coming from?

@mdanish98
Copy link
Contributor

Hi @StenGruener ,

Thanks a lot for raising this issue.
We reproduced this issue and have already found a fix. We will raise a PR addressing this issue soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In progress
Development

No branches or pull requests

2 participants