# Install and initialise

## Install and initialise

Before you can begin using Passport, you must install the XpansionChain SDK and initialise the Passport Client. The SDK Passport Module enables games & third-party applications to leverage XpansionChain authentication and wallet functionalities.

#### Pre-requisites[​](https://docs.x.immutable.com/docs/x/passport/install#pre-requisites) <a href="#pre-requisites" id="pre-requisites"></a>

* <mark style="color:blue;">An application registered in the XpansionChain Developer Hub</mark>

#### 1. Installing the XpansionChain SDK[​](https://docs.x.immutable.com/docs/x/passport/install#1-installing-the-immutable-sdk) <a href="#id-1-installing-the-immutable-sdk" id="id-1-installing-the-immutable-sdk"></a>

First, add the NPM package as a dependency to your application:

```
npm install @imtbl/sdk --save
# or
yarn add @imtbl/sdk
```

#### 2. Initialising Passport[​](https://docs.x.immutable.com/docs/x/passport/install#2-initialising-passport) <a href="#id-2-initialising-passport" id="id-2-initialising-passport"></a>

Next, we'll need to initialise the Passport client. The Passport constructor accepts a `PassportModuleConfiguration` object, which has the following interface:

```
interface PassportModuleConfiguration {
  baseConfig: XpansionChainConfiguration;
  clientId: string;
  logoutRedirectUri: string;
  logoutMode?: 'redirect' | 'silent'; // defaults to 'redirect'
  redirectUri: string;
  scope?: string;
  audience?: string;
}
```

**2.1 `baseConfig`**[**​**](https://docs.x.immutable.com/docs/x/passport/install#21-baseconfig)

An instance of an XpansionChain`Configuration`, which defines shared configuration across all the XpansionChain modules, such as the environment. This can be initialised as follows:

```
import { XpansionChainConfiguration, Environment } from '@imtbl/sdk';

const baseConfig = new XpansionChainConfiguration({
  environment: Environment.PRODUCTION,
});
```

INFO

Note: The `environment` argument can be one of the following:

| Environment Configuration | Description                                        |
| ------------------------- | -------------------------------------------------- |
| Environment.SANDBOX       | The default test network (currently, it is Goërli) |
| Environment.PRODUCTION    | The Ethereum mainnet network                       |

**2.2 `clientId`**[**​**](https://docs.x.immutable.com/docs/x/passport/install#22-clientid)

The unique identifier of the application that was registered in the XpansionChain Developer Hub

**2.3 `redirectUri`**[**​**](https://docs.x.immutable.com/docs/x/passport/install#23-redirecturi)

The URI of your application that users will be redirected to after successfully authenticating. This value must match one of the Callback URLs that have been set against your client in the XpansionChain Developer Hub

**2.4 `logoutRedirectUri`**[**​**](https://docs.x.immutable.com/docs/x/passport/install#24-logoutredirecturi)

The URI of your application that users will be redirected to after successfully logging out. This value must match one of the Logour URL's that have been set against your client in the XpansionChainDeveloper Hub

**2.5 `audience`**[**​**](https://docs.x.immutable.com/docs/x/passport/install#25-audience)

A string containing the audience(s) that the issued token is intended for, with each audience being separated by a space. Passport currently supports the following audiences:

* `platform_api`: The identifier for the XpansionChain protocol APIs

INFO

Note: The `platform_api` audience is required in order to interact with the XpansionChain protocol.

**2.6 `scope`**[**​**](https://docs.x.immutable.com/docs/x/passport/install#26-scope)

A string containing the scope(s) that specify what access privileges are being requested, with each scope being separated by a space. The following custom scopes are supported:

* `transact`: Allows the authenticating application to interact with the users Passport wallet.

In addition to the above, the following standard OIDC scopes are **strongly recommended**:

* `openid`: Informs the Authorization Server that the client is making an OpenID connect request.
* `offline_access`: Requests that an OAuth 2.0 Refresh Token be issued. The Refresh Token is used by Passport during registration to initialise the user's wallet.
* `email`: Requests that the client gains access to the users email address.

INFO

Note: The `transact`, `openid` & `offline_access` scopes are all currently required to correctly interact with Passport.

**2.7 Example initialisation**[**​**](https://docs.x.immutable.com/docs/x/passport/install#27-example-initialisation)

```
import { Environment, XpansionChainConfiguration, Passport } from '@imtbl/sdk';

const passport = new Passport({
  baseConfig: new XpansionChainConfiguration({
    environment: Environment.PRODUCTION,
  }),
  clientId: '<YOUR_CLIENT_ID>',
  redirectUri: 'https://example.com',
  logoutRedirectUri: 'https://example.com/logout',
  audience: 'platform_api',
  scope: 'openid offline_access email transact'
});
```

Note that the Passport constructor may throw the following error:

| Error Code             | Cause                                                            | Resolution                                                                                                                           |
| ---------------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ |
| INVALID\_CONFIGURATION | The Environment Configuration or OIDC Configuration is incorrect | Verify that you are passing an Environment Configuration and OIDC Configuration, and that all the mandatory properties have been set |

#### 3. Next steps[​](https://docs.x.immutable.com/docs/x/passport/install#3-next-steps) <a href="#id-3-next-steps" id="id-3-next-steps"></a>

You have now successfully installed and initialised the Passport module. Next up you will <mark style="color:blue;">integrate the login flow</mark> into your application.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xpansionchain-1.gitbook.io/xpansionchain/products/passport/install-and-configure/install-and-initialise.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
