> ## Documentation Index
> Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
> Use this file to discover all available pages before exploring further.

# Kotlin Manage Sessions

> Restore sessions, manage access, and sign out with the Kotlin OMS Wallet SDK.

Use the Kotlin SDK session APIs after authentication to restore wallet state, issue ID tokens, and manage credential access.

## Session State

Completed wallet sessions are restored automatically when the Android-backed `OMSClient` is created.

```kotlin theme={null}
val session = client.session

println("Wallet: ${session.walletAddress}")
println("Expires at: ${session.expiresAt}")
println("Login type: ${session.loginType}")
println("Email: ${session.sessionEmail}")
```

`client.session` only reports completed wallet-session state. Pending email OTP state is in memory, and OIDC redirect verifier state is stored internally for callback handling.

**Returns**

Returns `OMSClientSessionState` with `walletAddress`, `expiresAt`, `loginType`, and `sessionEmail`.

## Session Expiry Events

Register an `onSessionExpired` listener when the app should react as soon as the active wallet session expires.

```kotlin theme={null}
val unsubscribe = client.wallet.onSessionExpired { event ->
    println("Session expired at: ${event.expiredAt}")
    println("Expired wallet: ${event.session.walletAddress}")
}

// Call when the lifecycle owner no longer needs updates.
unsubscribe()
```

The SDK replays the latest expired-session event to new listeners until a new auth flow, new wallet session, or sign out clears it. Listener exceptions are ignored by the SDK so app callbacks do not change wallet operation results.

**Parameters**

| Parameter  | Type                                     | Description                                                                       |
| ---------- | ---------------------------------------- | --------------------------------------------------------------------------------- |
| `listener` | `(OMSClientSessionExpiredEvent) -> Unit` | Callback that receives `session` and `expiredAt` when the wallet session expires. |

**Returns**

Returns `() -> Unit`, an unsubscribe function that removes the listener.

## List Wallets

List wallets available to the authenticated credential.

```kotlin theme={null}
val wallets = client.wallet.listWallets()

for (wallet in wallets) {
    println("${wallet.id} ${wallet.type} ${wallet.address}")
}
```

**Parameters**

Takes no parameters.

**Returns**

Returns `List<Wallet>`.

## Get ID Token

Request an ID token for the active wallet session. Send this token to your backend when using backend wallet verification.

```kotlin theme={null}
val idToken = client.wallet.getIdToken(ttlSeconds = 300u)
```

**Parameters**

| Parameter      | Type                        | Description                                     |
| -------------- | --------------------------- | ----------------------------------------------- |
| `ttlSeconds`   | `UInt?`                     | Optional token lifetime in seconds.             |
| `customClaims` | `Map<String, JsonElement>?` | Optional custom claims to include in the token. |

**Returns**

Returns `String`.

## List Access

List credentials that currently have access to the active wallet.

```kotlin theme={null}
val credentials = client.wallet.listAccess(pageSize = 25u)

for (credential in credentials) {
    println("${credential.credentialId} ${credential.expiresAt} ${credential.isCaller}")
}
```

**Parameters**

| Parameter  | Type    | Description                                                 |
| ---------- | ------- | ----------------------------------------------------------- |
| `pageSize` | `UInt?` | Optional page size used while following Wallet API cursors. |

**Returns**

Returns `List<CredentialInfo>`.

## List Access Pages

Stream credential-access pages when your UI wants page-at-a-time rendering.

```kotlin theme={null}
import kotlinx.coroutines.flow.collect

client.wallet.listAccessPages(pageSize = 25u).collect { page ->
    for (credential in page.credentials) {
        println("${credential.credentialId} ${credential.isCaller}")
    }
}
```

**Parameters**

| Parameter  | Type    | Description                                          |
| ---------- | ------- | ---------------------------------------------------- |
| `pageSize` | `UInt?` | Optional page size used for each Wallet API request. |

**Returns**

Returns `Flow<ListAccessResponse>`.

## List Access Page

Fetch one credential-access page with an optional cursor.

```kotlin theme={null}
val page = client.wallet.listAccessPage(pageSize = 25u)
val nextCursor = page.page?.cursor
```

**Parameters**

| Parameter  | Type      | Description                                  |
| ---------- | --------- | -------------------------------------------- |
| `pageSize` | `UInt?`   | Optional page size for this request.         |
| `cursor`   | `String?` | Optional cursor returned by a previous page. |

**Returns**

Returns `ListAccessResponse`.

## Revoke Access

Revoke another credential's access to the active wallet.

```kotlin theme={null}
client.wallet.revokeAccess(targetCredentialId = "credential-id")
```

**Parameters**

| Parameter            | Type     | Description                             |
| -------------------- | -------- | --------------------------------------- |
| `targetCredentialId` | `String` | Credential ID returned by `listAccess`. |

**Returns**

Returns `Unit`.

## Sign Out

```kotlin theme={null}
client.wallet.signOut()
```

Signing out clears in-memory state, persisted wallet metadata, OIDC redirect state, and the Android Keystore credential used to sign wallet API requests.

**Parameters**

Takes no parameters.

**Returns**

Returns `Unit`.
