# getIdentityToken

> @web3auth/modal getIdentityToken | Embedded Wallets

Function to retrieve the identity token from Web3Auth.

:::note

This function will only return information based on the connected adapter. These details are not stored anywhere and are fetched from the adapter during the connection and remain in the session.

:::

### Usage

```ts
// Later in your code:
try {
  const idToken = await web3auth.getIdentityToken()
  console.log(idToken)
} catch (error) {
  console.error('Error authenticating user:', error)
}
```

### Return type

```typescript
getIdentityToken(): Promise<UserAuthInfo>

type UserAuthInfo = { idToken: string };
```

### Response format

The `idToken` is a JWT that can be decoded to get user information.

<Tabs
  defaultValue="social-login"
  values={[
    { label: "Social Login", value: "social-login" },
    { label: "External Wallet", value: "external-wallet" },
  ]}
>

<TabItem value="social-login">

<Tabs
  defaultValue="table"
  values={[
    { label: "Table", value: "table" },
    { label: "Type Declarations", value: "type" },
  ]}
>

<TabItem value="table">

| Parameter           | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `iat`               | `number` | The `iat` (issued at) claim identifies the time at which the JWT was issued.                                                                                                                                                                                                                                                                                                                    |
| `aud`               | `string` | The `aud` (audience) claim identifies the recipients the JWT is intended for (for example, the dapp `client_id`).                                                                                                                                                                                                                                                                               |
| `iss`               | `string` | The `iss` (issuer) claim identifies who issued the JWT (for example, Web3Auth `https://api.openlogin.com/`).                                                                                                                                                                                                                                                                                    |
| `email`             | `string` | (Optional) The email address of the user.                                                                                                                                                                                                                                                                                                                                                       |
| `name`              | `string` | (Optional) The name of the user.                                                                                                                                                                                                                                                                                                                                                                |
| `profileImage`      | `string` | (Optional) The profile image of the user .                                                                                                                                                                                                                                                                                                                                                      |
| `verifier`          | `string` | The Web3Auth verifier used during user login.                                                                                                                                                                                                                                                                                                                                                   |
| `verifierId`        | `string` | The unique user ID provided by the OAuth login provider.                                                                                                                                                                                                                                                                                                                                        |
| `aggregateVerifier` | `string` | (Optional) The name of the verifier if you are using a single ID (aggregate) verifier.                                                                                                                                                                                                                                                                                                          |
| `exp`               | `number` | The `exp` (expiration time) claim identifies the time on, or after which, the _JWT MUST NOT be accepted for processing_.                                                                                                                                                                                                                                                                        |
| `wallets`           | `array`  | List of wallets for which this token is issued:`curve`: Cryptographic curve used for the public key. Possible values are `secp256k1` (default) and `ed25519`. You can specify the curve in the login parameters.`type`: Wallet type. For social logins, this value is `web3auth_key`.`public_key`: Compressed public key derived using the specified curve. |

</TabItem>

<TabItem value="type">

`getIdentityToken(): Promise<UserAuthInfo>`

```tsx
export type UserAuthInfo = { idToken: string }
```

</TabItem>

</Tabs>

#### Sample response

```json
{
  "iat": 1655835494,
  "aud": "BCtbnOamqh0cJFEUYA0NB5YkvBECZ3HLZsKfvSRBvew2EiiKW3UxpyQASSR0artjQkiUOCHeZ_ZeygXpYpxZjOs",
  "iss": "https://api.openlogin.com/",
  "email": "xyz@xyz.com",
  "name": "John Doe",
  "profileImage": "https://lh3.googleusercontent.com/a/AATXAJx3lnGmHiM4K97uLo9Rb0AxOceH-dQCBSRqGbck=s96-c",
  "verifier": "torus",
  "verifierId": "xyz@xyz.com",
  "aggregateVerifier": "tkey-google-lrc",
  "exp": 1655921894,
  "wallets": [
    {
      "public_key": "035143318b83eb5d31611f8c03582ab1200494f66f5e11a67c34f5581f48c1b70b",
      "type": "web3auth_key",
      "curve": "secp256k1"
    }
  ]
}
```

</TabItem>

<TabItem value="external-wallet">

<Tabs
  defaultValue="table"
  values={[
    { label: "Table", value: "table" },
    { label: "Type Declarations", value: "type" },
  ]}
>

<TabItem value="table">

| Parameter | Type     | Description                                                                                                                                                                             |
| --------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `iat`     | `number` | The `iat` (issued at) claim identifies the time at which the JWT was issued.                                                                                                            |
| `aud`     | `string` | The audience claim identifies the recipients the JWT is intended for (for example, the website URL).                                                                                    |
| `iss`     | `string` | The issuer claim identifies who issued the JWT.Possible values: `torus-evm`, `torus-solana`, `metamask`, `phantom`, `walletconnect-v1`, `coinbase`, `solflare`.                   |
| `wallets` | `array`  | List of wallets for which this token is issued.- `address`: wallet public address.- `type`: network type such as `ethereum`, `solana`, or `starkware` for external wallets. |

</TabItem>

<TabItem value="type">

`getIdentityToken(): Promise<UserAuthInfo>`

```tsx
export type UserAuthInfo = { idToken: string }
```

</TabItem>

</Tabs>

#### Sample response

```json
{
  "iat": 1661158877,
  "issuer": "<issuer-name>",
  "audience": "https://requesting.website",
  "wallets": [
    {
      "address": "0x809d4310d578649d8539e718030ee11e603ee8f3",
      "type": "ethereum"
    }
  ],
  "exp": 1661245277
}
```

</TabItem>

</Tabs>

### Error handling

```javascript
try {
  const userInfo = await web3auth.getIdentityToken()
  // Use the token
} catch (error) {
  // Handle errors (e.g., user not connected, network issues)
  console.error('Authentication failed:', error)
}
```
