# ovok_sdk.auth.session

Canonical page: https://docs.ovok.com/python-sdk/reference/auth/session

The signed-in user's session and its JSON conversions.

## OvokReference [#ovokreference]

```python
OvokReference(reference: str, display: str | None = None)
```

A FHIR reference to a resource.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `reference` | `str` | Relative reference, such as `Patient/123`. |
| `display` | `str \| None` | Human-readable label, when the API sends one. |

## Session [#session]

```python
Session(
    access_token: str,
    refresh_token: str | None,
    expires_at_ms: int,
    project: OvokReference,
    profile: OvokReference,
)
```

The signed-in user's tokens, project and profile.

**Attributes**

| Name | Type | Description |
| --- | --- | --- |
| `access_token` | `str` | Bearer token; never shown in `repr`. |
| `refresh_token` | `str \| None` | Token that renews the session, if any; never shown in `repr`. |
| `expires_at_ms` | `int` | Access-token expiry in epoch milliseconds. |
| `project` | `OvokReference` | The project the user signed in to. |
| `profile` | `OvokReference` | The user's profile resource, such as a Patient or Practitioner. |

### is_stale_at() [#is_stale_at]

```python
is_stale_at(now_ms: int) -> bool
```

Whether the access token is within a minute of expiring at `now_ms`.

## session_from_login() [#session_from_login]

```python
session_from_login(tokens: Mapping[str, Any], now_ms: int) -> Session
```

Build a session from a sign-in response.

**Parameters**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `tokens` | `Mapping[str, Any]` |  | The camelCase body every Ovok sign-in route answers with. |
| `now_ms` | `int` |  | Current time in epoch milliseconds. |

**Returns**

- `Session`: The new session.

## session_after_refresh() [#session_after_refresh]

```python
session_after_refresh(session: Session, response: TokenResponse, now_ms: int) -> Session
```

Return `session` with the tokens from a refresh, keeping the old refresh token if none came back.

## reference_from_json() [#reference_from_json]

```python
reference_from_json(value: Mapping[str, Any]) -> OvokReference
```

Read a reference from its FHIR JSON shape.

## reference_to_json() [#reference_to_json]

```python
reference_to_json(reference: OvokReference) -> dict[str, Any]
```

Write a reference in its FHIR JSON shape.
