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

KNOX-3038 - The expires_in field in OAuthResource response returns the configured token TTL. #907

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ public Response getAuthenticationToken() {
// let's get the subset of the KnoxToken Response needed for OAuth
String accessToken = resp.responseMap.accessToken;
String passcode = resp.responseMap.passcode;
long expires = (long) resp.responseMap.map.get(EXPIRES_IN);
String tokenType = (String) resp.responseMap.map.get(TOKEN_TYPE);

// build and return the expected OAuth response
final HashMap<String, Object> map = new HashMap<>();
map.put(ACCESS_TOKEN, accessToken);
map.put(TOKEN_TYPE, tokenType);
map.put(EXPIRES_IN, expires);
map.put(EXPIRES_IN, getTokenLifetimeInSeconds());
map.put(ISSUED_TOKEN_TYPE, ISSUED_TOKEN_TYPE_ACCESS_TOKEN_VALUE);
// let's use the passcode as the refresh token
map.put(REFRESH_TOKEN, passcode);
Expand All @@ -103,8 +102,7 @@ public Response getAuthenticationToken() {
}
}

@Override
protected long getExpiry() {
private long getTokenLifetimeInSeconds() {
long secs = tokenTTL/1000;

String lifetimeStr = request.getParameter(LIFESPAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1657,21 +1657,8 @@ private static void validateRevocationResponse(final Response response,


private String getTagValue(String token, String tagName) {
if (!token.contains(tagName)) {
return null;
}
String searchString = "\"" + tagName + "\":";
String value = token.substring(token.indexOf(searchString) + searchString.length());
if (value.startsWith("\"")) {
value = value.substring(1);
}
if (value.contains("\"")) {
return value.substring(0, value.indexOf('\"'));
} else if (value.contains(",")) {
return value.substring(0, value.indexOf(','));
} else {
return value.substring(0, value.length() - 1);
}
final Map<String, String> tokenMap = JsonUtils.getMapFromJsonString(token);
return tokenMap == null ? null : tokenMap.get(tagName);
}

/**
Expand Down
Loading