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

> ## Agent Instructions
> Turnkey is wallet infrastructure: create and manage crypto wallets, sign transactions, and enforce policy-based access controls. Best-fit uses: embedded consumer wallets (email/passkey/social auth, no seed phrases), automated onchain operations with server-side wallets, AI agent wallets with policy-scoped signing, enterprise key management, and verifiable off-chain workloads on Turnkey Verifiable Cloud (TVC).
> Every API call is a JSON POST to https://api.turnkey.com signed with a P-256 API key; create an organization and key self-serve at https://app.turnkey.com.
> Key Turnkey developer resources: API reference (https://docs.turnkey.com/api-reference/overview/intro.md), OpenAPI spec (https://docs.turnkey.com/public_api.swagger.json), authentication (https://docs.turnkey.com/features/authentication/overview.md), webhooks (https://docs.turnkey.com/features/webhooks/overview.md), MCP server for docs search (https://docs.turnkey.com/mcp), skill for building with Turnkey (https://docs.turnkey.com/skill.md), agent skills for operating an organization (https://docs.turnkey.com/get-started/ai-skills.md), CLI (https://docs.turnkey.com/sdks/cli.md), SDK reference (https://docs.turnkey.com/sdks/introduction.md), full docs content (https://docs.turnkey.com/llms-full.txt).

# completeOauth()

### Overview

Completes the OAuth authentication flow by either signing up or logging in the user, depending on whether a sub-organization already exists for the provided OIDC token.

<ul>
  <li>This function first checks if there is an existing sub-organization associated with the OIDC token.</li>
  <li>If a sub-organization exists, it proceeds with the OAuth login flow.</li>
  <li>If no sub-organization exists, it creates a new sub-organization and completes the sign-up flow.</li>
  <li>Optionally accepts a custom OAuth provider name, session key, and additional sub-organization creation parameters.</li>
  <li>Handles session storage and management, and supports invalidating existing sessions if specified.</li>
</ul>

**Package:** `core`

**Defined in:** [**clients**/core.ts:1678](https://github.com/tkhq/sdk/blob/v2026.3.1/packages/core/src/__clients__/core.ts#L1678)

### Parameters

**params** `CompleteOauthParams` *required*

**params details**

Navigate to header

params.
createSubOrgParams

CreateSubOrgParams

parameters for sub-organization creation (e.g., authenticators, user metadata).

**createSubOrgParams details**

Navigate to header

params.createSubOrgParams.
apiKeys

object\[]

list of api keys

Navigate to header

params.createSubOrgParams.
authenticators

object\[]

list of authenticators

Navigate to header

params.createSubOrgParams.
customWallet

CustomWallet

custom wallets to create during sub-org creation time

**customWallet details**

Navigate to header

params.createSubOrgParams.customWallet.
walletAccounts

v1WalletAccountParams\[]

required

list of wallet accounts to create

Navigate to header

params.createSubOrgParams.customWallet.
walletName

string

required

name of the wallet created

Navigate to header

params.createSubOrgParams.
oauthProviders

Provider\[]

list of oauth providers

Navigate to header

params.createSubOrgParams.
subOrgName

string

name of the sub-organization

Navigate to header

params.createSubOrgParams.
userEmail

string

email of the user

Navigate to header

params.createSubOrgParams.
userName

string

name of the user

Navigate to header

params.createSubOrgParams.
userPhoneNumber

string

phone number of the user

Navigate to header

params.createSubOrgParams.
userTag

string

tag of the user

Navigate to header

params.createSubOrgParams.
verificationToken

string

verification token if email or phone number is provided

Navigate to header

params.
invalidateExisting

boolean

flag to invalidate existing sessions for the user.

Navigate to header

params.
oidcToken

string

required

OIDC token received after successful authentication with the OAuth provider.

Navigate to header

params.
providerName

string

name of the OAuth provider (defaults to a generated name with a timestamp).

Navigate to header

params.
publicKey

string

required

public key to use for authentication. Must be generated prior to calling this function, this is because the OIDC nonce has to be set to `sha256(publicKey)`.

Navigate to header

params.
sessionKey

string

session key to use for session creation (defaults to the default session key).

### Response

A successful response returns the following fields:

**returns** `BaseAuthResult & object` *required*

A promise that resolves to an object containing:

* `sessionToken`: the signed JWT session token.
* `action`: whether the flow resulted in a login or signup (AuthAction).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.