KInMemoryTokenStore

class KInMemoryTokenStore(initialAccessToken: String? = null, initialRefreshToken: String? = null) : KTokenStore(source)

In-memory KTokenStore implementation.

Tokens are never persisted — they are lost when the instance is discarded. Intended for unit tests and mock environments where persistence is undesirable.

Usage:

// In tests
val store = KInMemoryTokenStore()
val session = KSessionManager(store)

// Pre-seed a token for authenticated tests
val store = KInMemoryTokenStore(
initialAccessToken = "test-access-token",
initialRefreshToken = "test-refresh-token",
)

Parameters

initialAccessToken

Optional pre-seeded access token.

initialRefreshToken

Optional pre-seeded refresh token.

Constructors

Link copied to clipboard
constructor(initialAccessToken: String? = null, initialRefreshToken: String? = null)

Functions

Link copied to clipboard
open suspend override fun clear()

Removes all stored tokens.

Link copied to clipboard
open suspend override fun getAccessToken(): String?

Returns the current access token, or null if none is stored.

Link copied to clipboard
open suspend override fun getRefreshToken(): String?

Returns the current refresh token, or null if none is stored.

Link copied to clipboard
open suspend override fun saveTokens(accessToken: String?, refreshToken: String?)

Persists both tokens.