Skip to content

Commit

Permalink
Added token refresh api timeout to avoid buffer overflow of requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
SravanThotakura05 committed May 14, 2024
1 parent 90de8b1 commit 0995bc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ quarkus.solace.vpn=default
quarkus.solace.authentication.scheme=AUTHENTICATION_SCHEME_OAUTH2
quarkus.solace.oidc.client-name=solace // client name provided in oidc client config below
quarkus.solace.oidc.refresh.interval=50s // Refresh interval should be less than access token expiry time. Otherwise extension will fail to update access token in solace session.
quarkus.solace.oidc.refresh.timeout=10s // Token Refresh API timeout. Default is set to 10 seconds.
quarkus.oidc-client.solace.auth-server-url=http://localhost:7777/auth/realms/master
quarkus.oidc-client.solace.client-id=<client-id>
Expand All @@ -142,6 +143,7 @@ quarkus.solace.tls.trust-store-type=
quarkus.solace.tls.trust-store-password=
quarkus.solace.oidc.client-name=solace // client name provided in oidc client config below
quarkus.solace.oidc.refresh.interval=50s // Refresh interval should be less than access token expiry time. Otherwise extension will fail to update access token in solace session.
quarkus.solace.oidc.refresh.timeout=10s // Token Refresh API timeout. Default is set to 10 seconds.
quarkus.oidc-client.solace.auth-server-url=http://localhost:7777/auth/realms/master
quarkus.oidc-client.solace.client-id=<client-id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class OidcProvider {
@ConfigProperty(name = "quarkus.solace.oidc.refresh.interval", defaultValue = "60s")
Duration duration;

@ConfigProperty(name = "quarkus.solace.oidc.refresh.timeout", defaultValue = "10s")
Duration refreshTimeout;

@ConfigProperty(name = "quarkus.solace.oidc.client-name")
Optional<String> oidcClientName;

Expand All @@ -43,15 +46,17 @@ Tokens getToken() {
void init(MessagingService service) {
OidcClient client = getClient();
Multi.createFrom().ticks().every(duration)
.onOverflow().drop()
.emitOn(Infrastructure.getDefaultWorkerPool())
.call(() -> {
if (lastToken != null && lastToken.getRefreshToken() != null
&& lastToken.isAccessTokenWithinRefreshInterval()) {
Log.info("Refreshing access token for Solace connection");
return client.refreshTokens(lastToken.getRefreshToken()).invoke(tokens -> lastToken = tokens);
return client.refreshTokens(lastToken.getRefreshToken()).invoke(tokens -> lastToken = tokens).ifNoItem()
.after(refreshTimeout).fail();
} else {
Log.info("Acquiring access token for Solace connection");
return client.getTokens().invoke(tokens -> lastToken = tokens);
return client.getTokens().invoke(tokens -> lastToken = tokens).ifNoItem().after(refreshTimeout).fail();
}
})
.onFailure().call(t -> {
Expand Down

0 comments on commit 0995bc0

Please sign in to comment.