# Integration Guide: E-Wallet SSO

This guide describes how to integrate the Innovorder E-Wallet (e-rechargement) interface into an external guest application (e.g., via a WebView) using a Single Sign-On (SSO) mechanism.

#### Prerequisites

You will need the following information provided by Innovorder Support:

-   **Brand ID**: Unique identifier for your brand.
-   **JWT Secret**: A private key shared between your backend and Innovorder.

### 1\. Generate the JWT

First, your backend must generate a signed JWT containing the user's identity. This token serves as a proof of authentication.

#### Payload Structure

**JWT Payload**

```json
{
  "email": "user@example.com",
  "brandId": 12345,
  "date": "2023-10-27T10:00:00.000Z" // ISO 8601 String
}
```

#### Example (Node.js)

**Sign JWT**

```javascript
const jwt = require('jsonwebtoken');

const payload = {
  email: "user@example.com",
  brandId: 691,
  date: new Date().toISOString()
};

const jwtSecret = "YOUR_SHARED_SECRET_KEY";
const signedJwt = jwt.sign(payload, jwtSecret);

console.log(signedJwt); 
// Output: eyJhbGciOiJIUzI1NiIsIn...
```

### 2\. Exchange for Access Token

Unlike the Web Ordering SSO, the E-Wallet requires a valid API `accessToken` to perform the auto-login. You must exchange your signed JWT for an Innovorder `accessToken` via the API.

### `POST /oauth/login` - Exchange JWT

Send the generated JWT to receive an accessToken. The access token is valid for 24 hours; when it expires the API responds with a 401 error (token\_expired) and you must exchange a fresh JWT again.

#### Request Body

```json
{
  "autoLoginJWT": "eyJhbGciOiJIUzI1NiIsIn..."
}
```

##### Request Body Properties

Every field in the example is listed below. Explicit requiredness is shown when the endpoint contract defines it.

| Property | Type | Example | Description |
| --- | --- | --- | --- |
| autoLoginJWT | string | "eyJhbGciOiJIUzI1NiIsIn..." | The auto login jwt value. |

#### Response

```json
{
  "access_token": "VALID_ACCESS_TOKEN_XYZ...",
  "token_type": "Bearer"
}
```

##### Response Properties

Every field in the example is listed below. Explicit requiredness is shown when the endpoint contract defines it.

| Property | Type | Example | Description |
| --- | --- | --- | --- |
| access\_token | string | "VALID\_ACCESS\_TOKEN\_XYZ..." | The access token value. |
| token\_type | string | "Bearer" | The token type value. |

### 3\. Redirect the User

Construct the final URL by appending the received `accessToken` to the `autoLoginByAccessToken` query parameter. Open this URL in your WebView or iframe.

https://ewallet.innovorder.fr/&lt;brandId&gt;/home?autoLoginByAccessToken=&lt;accessToken&gt;
