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

# Swift SDK Authentication

> Authenticate users and resolve wallets with the Swift OMS Wallet SDK.

The Swift SDK supports email OTP and Google sign-in through OIDC ID-token authentication or authorization-code redirect authentication. Authentication returns an active wallet by default. Use manual wallet selection when your app should present wallet choices.

## Start Email Auth

Send a one-time code to the user's email address.

```swift theme={null}
try await oms.wallet.startEmailAuth(email: "user@example.com")
```

**Parameters**

| Parameter | Type     | Description                                    |
| --------- | -------- | ---------------------------------------------- |
| `email`   | `String` | Email address that receives the one-time code. |

**Returns**

Returns `Void`.

## Complete Email Auth

Complete the flow with the code entered by the user. Automatic mode returns an active wallet when possible.

```swift theme={null}
let result = try await oms.wallet.completeEmailAuth(code: "123456")

if case let .walletSelected(walletAddress, wallet, _, _) = result {
    print("Wallet address:", walletAddress)
    print("Wallet ID:", wallet.id)
}
```

Use manual wallet selection when the app needs to choose between wallets before activating one.

```swift theme={null}
let selectionResult = try await oms.wallet.completeEmailAuth(
    code: "123456",
    walletSelection: .manual,
    walletType: .ethereum
)

if case let .walletSelection(selection) = selectionResult {
    try await selection.createAndSelectWallet(reference: "main")
}
```

**Parameters**

| Parameter                | Type                      | Description                                                                      |
| ------------------------ | ------------------------- | -------------------------------------------------------------------------------- |
| `code`                   | `String`                  | One-time code entered by the user.                                               |
| `walletSelection`        | `WalletSelectionBehavior` | Defaults to `.automatic`. Use `.manual` to receive a pending wallet selection.   |
| `walletType`             | `WalletType`              | Optional wallet type. Defaults to `.ethereum`.                                   |
| `sessionLifetimeSeconds` | `UInt32`                  | Optional requested wallet API session lifetime in seconds. Defaults to one week. |

**Returns**

Returns `CompleteAuthResult`, either `.walletSelected(...)` or `.walletSelection(PendingWalletSelection)`.

## Sign In With OIDC Token

Use OIDC ID-token auth for providers such as Google Sign-In. Pass the provider token plus the issuer and audience used to mint it.

```swift theme={null}
let result = try await oms.wallet.signInWithOidcIdToken(
    idToken: googleIdToken,
    issuer: "https://accounts.google.com",
    audience: "YOUR_WEB_CLIENT_ID"
)

if case let .walletSelected(walletAddress, wallet, _, _) = result {
    print("Wallet address:", walletAddress)
    print("Wallet ID:", wallet.id)
}
```

Use manual wallet selection when the app needs to choose between wallets before activating one.

```swift theme={null}
let result = try await oms.wallet.signInWithOidcIdToken(
    idToken: googleIdToken,
    issuer: "https://accounts.google.com",
    audience: "YOUR_WEB_CLIENT_ID",
    walletSelection: .manual
)

if case let .walletSelection(selection) = result {
    try await selection.createAndSelectWallet(reference: "main")
}
```

This method accepts the OIDC ID token directly. Use `startOidcRedirectAuth` and `handleOidcRedirectCallback` for authorization-code PKCE redirect auth.

**Parameters**

| Parameter                | Type                      | Description                                                                      |
| ------------------------ | ------------------------- | -------------------------------------------------------------------------------- |
| `idToken`                | `String`                  | OIDC ID token from the identity provider.                                        |
| `issuer`                 | `String`                  | Expected token issuer, such as `https://accounts.google.com`.                    |
| `audience`               | `String`                  | Expected token audience.                                                         |
| `walletType`             | `WalletType`              | Optional wallet type. Defaults to `.ethereum`.                                   |
| `walletSelection`        | `WalletSelectionBehavior` | Defaults to `.automatic`. Use `.manual` to receive a pending wallet selection.   |
| `sessionLifetimeSeconds` | `UInt32`                  | Optional requested wallet API session lifetime in seconds. Defaults to one week. |

**Returns**

Returns `CompleteAuthResult`, either `.walletSelected(...)` or `.walletSelection(PendingWalletSelection)`.

## Start OIDC Redirect Auth

Start a Google authorization-code PKCE flow and open the returned authorization URL with a system auth browser.

```swift theme={null}
let redirect = try await oms.wallet.startOidcRedirectAuth(
    provider: OidcProviders.google(),
    redirectUri: "yourapp://auth/callback"
)

print("Open:", redirect.authorizationUrl)
```

Register the callback scheme, such as `yourapp`, in your app target before using redirect auth.

**Parameters**

| Parameter         | Type                 | Description                                                                                                          |
| ----------------- | -------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `provider`        | `OidcProviderConfig` | Google provider configuration returned by `OidcProviders.google()`.                                                  |
| `redirectUri`     | `String`             | App callback URL that receives the provider redirect. Configure this URL scheme or universal link in the app target. |
| `walletType`      | `WalletType`         | Optional wallet type. Defaults to `.ethereum`.                                                                       |
| `loginHint`       | `String?`            | Optional Google `login_hint`. When omitted for Google, the SDK can reuse the previous session email.                 |
| `authorizeParams` | `[String: String]`   | Extra authorization query parameters passed to the provider.                                                         |

**Returns**

Returns `StartOidcRedirectAuthResult` with the provider `authorizationUrl`. `state` and `challenge` are SDK-managed values.

## Handle OIDC Redirect Callback

Pass incoming app-link URLs to the callback handler. It is safe to call for unrelated links.

```swift theme={null}
let result = try await oms.wallet.handleOidcRedirectCallback(callbackUrl)

switch result {
case .completed(let wallet):
    print("Wallet address:", wallet.address)
case .walletSelection(let selection):
    try await selection.createAndSelectWallet()
case .notOidcRedirectCallback, .noPendingAuth:
    break
case .failed(let error):
    throw error
}
```

**Parameters**

| Parameter                | Type                      | Description                                                                      |
| ------------------------ | ------------------------- | -------------------------------------------------------------------------------- |
| `callbackUrl`            | `String?`                 | Incoming app-link URL.                                                           |
| `walletSelection`        | `WalletSelectionBehavior` | Defaults to `.automatic`. Use `.manual` to receive a pending wallet selection.   |
| `sessionLifetimeSeconds` | `UInt32`                  | Optional requested wallet API session lifetime in seconds. Defaults to one week. |

**Returns**

Returns `OidcRedirectAuthResult`.

## Use Wallet

Activate an existing wallet by server-side wallet ID.

```swift theme={null}
try await oms.wallet.useWallet(walletId: "wallet-id")
```

**Parameters**

| Parameter  | Type     | Description                                               |
| ---------- | -------- | --------------------------------------------------------- |
| `walletId` | `String` | Wallet ID returned by auth completion or `listWallets()`. |

**Returns**

Returns `WalletActivationResult`.

## Create Wallet

Create and activate a new wallet for the authenticated user.

```swift theme={null}
let result = try await oms.wallet.createWallet(reference: "main")

print("New wallet:", result.walletAddress)
```

**Parameters**

| Parameter    | Type         | Description                                     |
| ------------ | ------------ | ----------------------------------------------- |
| `walletType` | `WalletType` | Wallet type to create. Defaults to `.ethereum`. |
| `reference`  | `String?`    | Optional app-defined wallet reference.          |

**Returns**

Returns `WalletActivationResult`.
