Interface TokenStore

All Known Implementing Classes:
FileTokenStore, InMemoryTokenStore

public interface TokenStore
Token Store Interface Token 存储接口

Defines the contract for storing and retrieving OAuth2 tokens.

定义存储和检索 OAuth2 令牌的契约。

Implementations | 实现:

Usage Examples | 使用示例:

// Use in-memory store
TokenStore store = new InMemoryTokenStore();
store.save("user-1", token);

// Retrieve token
Optional<OAuth2Token> token = store.load("user-1");

// Custom implementation
TokenStore redisStore = new TokenStore() {
    @Override
    public void save(String key, OAuth2Token token) {
        redis.set("oauth2:" + key, serialize(token));
    }
    // ... other methods
};

Features | 主要功能:

  • SPI for OAuth2 token persistence - OAuth2令牌持久化的SPI接口
  • Pluggable storage backend support - 可插拔的存储后端支持

Security | 安全性:

  • Thread-safe: Implementation-dependent - 线程安全: 取决于实现
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-oauth2 V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Delete a token by key 通过键删除令牌
    void
    Delete all stored tokens 删除所有存储的令牌
    default boolean
    Check if a token exists 检查令牌是否存在
    default Set<String>
    Get all stored keys 获取所有存储的键
    load(String key)
    Load a token by key 通过键加载令牌
    void
    save(String key, OAuth2Token token)
    Save a token with the given key 使用给定的键保存令牌
    default int
    Get the number of stored tokens 获取存储的令牌数量
  • Method Details

    • save

      void save(String key, OAuth2Token token)
      Save a token with the given key 使用给定的键保存令牌
      Parameters:
      key - the storage key | 存储键
      token - the token to save | 要保存的令牌
    • load

      Load a token by key 通过键加载令牌
      Parameters:
      key - the storage key | 存储键
      Returns:
      the token if found | 找到的令牌
    • delete

      void delete(String key)
      Delete a token by key 通过键删除令牌
      Parameters:
      key - the storage key | 存储键
    • deleteAll

      void deleteAll()
      Delete all stored tokens 删除所有存储的令牌
    • exists

      default boolean exists(String key)
      Check if a token exists 检查令牌是否存在
      Parameters:
      key - the storage key | 存储键
      Returns:
      true if exists | 存在返回 true
    • keys

      default Set<String> keys()
      Get all stored keys 获取所有存储的键
      Returns:
      the set of keys | 键集合
    • size

      default int size()
      Get the number of stored tokens 获取存储的令牌数量
      Returns:
      the count | 数量