> ## 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` reports completed wallet-session state. If an auth flow is interrupted before completion, complete it through the matching callback flow or start authentication again.

**Returns**

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

`expiresAt` is an ISO-8601 timestamp string returned by the wallet API.

## 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}")
}
```

Keep the listener active while the lifecycle owner needs updates. Call `unsubscribe()` during cleanup.

**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.

`event.expiredAt` is an ISO-8601 timestamp string returned by the wallet API.

## 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](/wallets/sdk/guides/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 app-provided claims. Backends should treat them as client-provided context unless they control the values. |

**Returns**

Returns `String`.

## List Access

List wallet access grants for account-management UI.

```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 for paginated access results. |

**Returns**

Returns `List<CredentialInfo>`.

## Advanced: 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 for each access-list request. |

**Returns**

Returns `Flow<ListAccessResponse>`.

## Advanced: 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 the saved wallet session and authentication state. The user must authenticate again before wallet operations.

**Parameters**

Takes no parameters.

**Returns**

Returns `Unit`.
