Skip to content

Commit

Permalink
Add failover to accessToken for OAuth2 with refresh token
Browse files Browse the repository at this point in the history
Right now when we can't deserialize tokens, that we expect to be encrypted
we are failing authentication and send challenges to clients. With this change
we will allow for further processing, in case when the format of the token is not parsable
- meaning that it's not an JWEToken, but might be a valid OAuth2 token that could be
handled by further processing.

This case occurs for cases when a tool sends valid accessToken
obtained outside from Trino, but has configured Oauth2 with refresh tokens enabled, for other
clients that benefit from that flow directly
  • Loading branch information
s2lomon authored and kokosing committed Nov 10, 2022
1 parent 9feb3d1 commit 70be36d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public TokenPair deserialize(String token)
claims.get(REFRESH_TOKEN_KEY, String.class));
}
catch (ParseException ex) {
throw new IllegalArgumentException("Malformed jwt token", ex);
return TokenPair.accessToken(token);
}
catch (JOSEException ex) {
throw new IllegalArgumentException("Decryption failed", ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ public void testTokenDeserializationAfterTimeoutAndExpirationExtension()
.isExactlyInstanceOf(ExpiredJwtException.class);
}

@Test
public void testTokenDeserializationWhenNonJWETokenIsPassed()
throws Exception
{
JweTokenSerializer serializer = tokenSerializer(new TestingClock(), succinctDuration(12, MINUTES));
String nonJWEToken = "non_jwe_token";

TokenPair tokenPair = serializer.deserialize(nonJWEToken);

assertThat(tokenPair.getAccessToken()).isEqualTo(nonJWEToken);
assertThat(tokenPair.getRefreshToken()).isEmpty();
}

private JweTokenSerializer tokenSerializer(Clock clock, Duration tokenExpiration)
throws GeneralSecurityException, KeyLengthException
{
Expand Down

0 comments on commit 70be36d

Please sign in to comment.