This client provides access to Centrifugo's token management functionality, allowing you to revoke individual tokens or invalidate all tokens for users. This is essential for implementing secure authentication flows and session management.
Key features:
- Revoke specific tokens by UID
- Invalidate all user tokens with filtering options
- Time-based token invalidation
- Channel-specific token invalidation
- Since:
- 1.0.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionInvalidate all tokens for a user.default InvalidateUserTokensResponseinvalidateUserTokens(Function<InvalidateUserTokensRequest.Builder, InvalidateUserTokensRequest.Builder> fn) Invalidate all tokens for a user.revokeToken(RevokeTokenRequest request) Revoke a token.default RevokeTokenResponserevokeToken(String uid) Revoke a token.
-
Method Details
-
revokeToken
Revoke a token.Revokes a specific token by its unique identifier (UID). Once revoked, the token will be considered invalid and connections using it will be terminated with an appropriate disconnect reason.
Features:
- Immediate token invalidation
- Automatic connection termination
- Optional expiration time for revocation
- Precise token targeting by UID
Use cases:
- Implementing logout functionality
- Revoking compromised tokens
- Session management and cleanup
- Security incident response
Example:
RevokeTokenRequest request = RevokeTokenRequest.builder().uid("token-uuid-here") .build(); RevokeTokenResponse response = client.revokeToken(request);Example with expiration:
long futureTime = System.currentTimeMillis() / 1000 + 3600; // 1 hour from now RevokeTokenRequest request = RevokeTokenRequest.builder().uid("token-uuid-here") .expireAt(futureTime).build(); RevokeTokenResponse response = client.revokeToken(request);- Parameters:
request- the revoke token request containing token UID and optional expiration- Returns:
- the revoke token response
- See Also:
-
revokeToken
Revoke a token.Revokes a specific token by its unique identifier (UID). Once revoked, the token will be considered invalid and connections using it will be terminated with an appropriate disconnect reason.
Features:
- Immediate token invalidation
- Automatic connection termination
- Optional expiration time for revocation
- Precise token targeting by UID
Use cases:
- Implementing logout functionality
- Revoking compromised tokens
- Session management and cleanup
- Security incident response
Example:
RevokeTokenRequest request = RevokeTokenRequest.builder().uid("token-uuid-here") .build(); RevokeTokenResponse response = client.revokeToken(request);Example with expiration:
long futureTime = System.currentTimeMillis() / 1000 + 3600; // 1 hour from now RevokeTokenRequest request = RevokeTokenRequest.builder().uid("token-uuid-here") .expireAt(futureTime).build(); RevokeTokenResponse response = client.revokeToken(request);- Parameters:
uid- the unique identifier of the token to revoke- Returns:
- the revoke token response
- See Also:
-
invalidateUserTokens
Invalidate all tokens for a user.Invalidates all tokens associated with a specific user. This is a powerful operation that can terminate all user sessions across all devices and applications. Supports various filtering options for fine-grained control.
Invalidation options:
- All user tokens
- Tokens issued before a specific time
- Channel-specific tokens only
- Optional expiration time for invalidation
Use cases:
- Global user logout (all devices)
- Security breach response
- Account compromise mitigation
- Forced re-authentication
- Password change enforcement
Example - invalidate all user tokens:
InvalidateUserTokensRequest request = InvalidateUserTokensRequest.builder() .user("user123").build(); InvalidateUserTokensResponse response = client.invalidateUserTokens(request);Example - invalidate tokens issued before a specific time:
long passwordChangeTime = System.currentTimeMillis() / 1000; InvalidateUserTokensRequest request = InvalidateUserTokensRequest.builder() .user("user123").issuedBefore(passwordChangeTime).build(); InvalidateUserTokensResponse response = client.invalidateUserTokens(request);Example - invalidate channel-specific tokens:
InvalidateUserTokensRequest request = InvalidateUserTokensRequest.builder() .user("user123").channel("private:user123").build(); InvalidateUserTokensResponse response = client.invalidateUserTokens(request);- Parameters:
request- the invalidate user tokens request containing user ID and filtering options- Returns:
- the invalidate user tokens response
- See Also:
-
invalidateUserTokens
default InvalidateUserTokensResponse invalidateUserTokens(Function<InvalidateUserTokensRequest.Builder, InvalidateUserTokensRequest.Builder> fn) Invalidate all tokens for a user.Invalidates all tokens associated with a specific user. This is a powerful operation that can terminate all user sessions across all devices and applications. Supports various filtering options for fine-grained control.
Invalidation options:
- All user tokens
- Tokens issued before a specific time
- Channel-specific tokens only
- Optional expiration time for invalidation
Use cases:
- Global user logout (all devices)
- Security breach response
- Account compromise mitigation
- Forced re-authentication
- Password change enforcement
Example - invalidate all user tokens:
InvalidateUserTokensRequest request = InvalidateUserTokensRequest.builder() .user("user123").build(); InvalidateUserTokensResponse response = client.invalidateUserTokens(request);Example - invalidate tokens issued before a specific time:
long passwordChangeTime = System.currentTimeMillis() / 1000; InvalidateUserTokensRequest request = InvalidateUserTokensRequest.builder() .user("user123").issuedBefore(passwordChangeTime).build(); InvalidateUserTokensResponse response = client.invalidateUserTokens(request);Example - invalidate channel-specific tokens:
InvalidateUserTokensRequest request = InvalidateUserTokensRequest.builder() .user("user123").channel("private:user123").build(); InvalidateUserTokensResponse response = client.invalidateUserTokens(request);- Parameters:
fn- the function to configure the invalidate user tokens request- Returns:
- the invalidate user tokens response
- See Also:
-