Skip to content

Commit

Permalink
Add logging to get information about refresh token version
Browse files Browse the repository at this point in the history
  • Loading branch information
cYKatherine committed Jun 7, 2024
1 parent b8f5cd4 commit 9acf223
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import com.uid2.shared.model.KeysetKey;
import com.uid2.shared.model.TokenVersion;
import io.vertx.core.buffer.Buffer;
import org.slf4j.LoggerFactory;

import java.time.Instant;
import java.util.Base64;

public class EncryptedTokenEncoder implements ITokenEncoder {

private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(EncryptedTokenEncoder.class);
private final KeyManager keyManager;

public EncryptedTokenEncoder(KeyManager keyManager) {
Expand Down Expand Up @@ -264,8 +265,10 @@ public byte[] encode(RefreshToken t, Instant asOf) {

switch (t.version) {
case V2:
LOGGER.info(String.format("Serving refresh token V2"));
return encodeV2(t, serviceKey);
case V3:
LOGGER.info(String.format("Serving refresh token V3"));
return encodeV3(t, serviceKey);
default:
throw new ClientInputValidationException("RefreshToken version " + t.version + " not supported");
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1778,13 +1778,27 @@ private void recordOptOutStatusEndpointStats(RoutingContext rc, int inputCount,
optOutDistSummary.record(optOutCount);
}

public TokenVersion getRefreshTokenVersion(String s) {
if (s != null && !s.isEmpty()) {
final byte[] bytes = EncodingUtils.fromBase64(s);
final Buffer b = Buffer.buffer(bytes);
if (b.getByte(1) == TokenVersion.V3.rawVersion) {
return TokenVersion.V3;
} else if (b.getByte(0) == TokenVersion.V2.rawVersion) {
return TokenVersion.V2;
}
}
return null;
}

private RefreshResponse refreshIdentity(RoutingContext rc, String tokenStr) {
final RefreshToken refreshToken;
try {
if (AuthMiddleware.isAuthenticated(rc)) {
rc.put(Const.RoutingContextData.SiteId, AuthMiddleware.getAuthClient(ClientKey.class, rc).getSiteId());
}

LOGGER.info(String.format("Site id %s requested to decode refresh token %s", AuthMiddleware.getAuthClient(rc).getSiteId(), this.getRefreshTokenVersion(tokenStr)));
refreshToken = this.encoder.decodeRefreshToken(tokenStr);
} catch (ClientInputValidationException cie) {
return RefreshResponse.Invalid;
Expand Down

0 comments on commit 9acf223

Please sign in to comment.