[KEYCLOAK-1205] Fix BearerAuthFilter refreshing token after it's expired
This commit is contained in:
parent
47da227809
commit
b1b149e0c3
3 changed files with 14 additions and 4 deletions
|
@ -26,7 +26,7 @@ public class Keycloak {
|
|||
|
||||
target = client.target(config.getServerUrl());
|
||||
|
||||
target.register(new BearerAuthFilter(tokenManager.getAccessTokenString()));
|
||||
target.register(new BearerAuthFilter(tokenManager));
|
||||
}
|
||||
|
||||
public static Keycloak getInstance(String serverUrl, String realm, String username, String password, String clientId, String clientSecret){
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.keycloak.admin.client.resource;
|
||||
|
||||
import org.keycloak.admin.client.token.TokenManager;
|
||||
|
||||
import javax.ws.rs.client.ClientRequestContext;
|
||||
import javax.ws.rs.client.ClientRequestFilter;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
@ -11,14 +13,23 @@ import java.io.IOException;
|
|||
public class BearerAuthFilter implements ClientRequestFilter {
|
||||
|
||||
private final String tokenString;
|
||||
private final TokenManager tokenManager;
|
||||
|
||||
public BearerAuthFilter(String tokenString) {
|
||||
this.tokenString = tokenString;
|
||||
this.tokenManager = null;
|
||||
}
|
||||
|
||||
public BearerAuthFilter(TokenManager tokenManager) {
|
||||
this.tokenManager = tokenManager;
|
||||
this.tokenString = null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void filter(ClientRequestContext requestContext) throws IOException {
|
||||
String authHeader = "Bearer " + tokenString;
|
||||
String authHeader = "Bearer " + (tokenManager != null ? tokenManager.getAccessTokenString() : tokenString);
|
||||
|
||||
requestContext.getHeaders().add(HttpHeaders.AUTHORIZATION, authHeader);
|
||||
}
|
||||
|
||||
|
|
|
@ -66,8 +66,7 @@ public class TokenManager {
|
|||
|
||||
Form form = new Form()
|
||||
.param("grant_type", "refresh_token")
|
||||
.param("username", config.getUsername())
|
||||
.param("password", config.getPassword());
|
||||
.param("refresh_token", currentToken.getRefreshToken());
|
||||
|
||||
if(config.isPublicClient()){
|
||||
form.param("client_id", config.getClientId());
|
||||
|
|
Loading…
Reference in a new issue