> For the complete documentation index, see [llms.txt](https://id-docs.fsl.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://id-docs.fsl.com/developers/univeral-login.md).

# Univeral Login

{% hint style="info" %}
API\_BASE\_URL: <https://id.fsl.com>&#x20;
{% endhint %}

## Sign in with FSL ID

It is a universal login solution to be integrated into your products. The solution is built upon [OAuth 2.0](https://oauth.net/2/). The integration experience is pretty much similar to OAuth 2.0.

### Get Authorization Code

<mark style="color:green;">`Get`</mark> `/api/account/oauth/authorize`

Get the authorization code to start with.

**Parameters**

<table><thead><tr><th width="200">Name</th><th width="128">Mandatory?</th><th>Description</th></tr></thead><tbody><tr><td><code>response_type</code></td><td>Y</td><td>Grant type. Use the value "<strong><code>code</code></strong>" to get an <code>authorization code.</code></td></tr><tr><td><code>appkey</code></td><td>Y</td><td>The unique <code>appkey</code> for your App.</td></tr><tr><td><code>redirect_uri</code></td><td>Y</td><td>The redirect URL address after authorization success. The <code>authorization code</code> with be returned to the redirect URL. <br><br>The <code>redirect_uri</code>should be url-encoded. </td></tr><tr><td><code>scope</code></td><td>N</td><td><a href="/pages/yWm6wJVpVq6MSmY60RDa">Grant Scope</a>. Refer to the definitions for more details. Only request <code>basic</code> scope when the parameter is not given.</td></tr><tr><td><code>state</code></td><td>N</td><td>A developer-specified parameter to validate or bring special information. The parameter will be brought to the redirect URL.  </td></tr></tbody></table>

**Returns**

Authorization code which will be expired in 5 minutes.

**Request Example**

```sh
curl https://$API_BASE_URL/api/account/oauth/authorize \
-d "response_type=code" \
-d "appkey=1234" \
-d "redirect_uri=https%3A%2F%2Fmydomain.com%2Fredirect" \
-d "scope=basic" \
-d "state=test" 
```

**Response**

{% tabs %}
{% tab title="200" %}

```json
https://mydomain.com/redirect?code=AUTHORIZATION_CODE&state=test
```

{% endtab %}
{% endtabs %}

After the FSL ID verification and scope grant success, the system will redirect to the redirect URL with the `authorization code` and `state` parameter.

### Get access token and refresh token

<mark style="color:green;">`POST`</mark>  `/api/account/oauth/token`

Get access token and refresh token

**Header**

| Name         | Value                               |
| ------------ | ----------------------------------- |
| Content-Type | `application/x-www-form-urlencoded` |

**Parameters**

<table><thead><tr><th width="182">Name</th><th width="152">Mandatory?</th><th>Description</th></tr></thead><tbody><tr><td><code>authorization_code</code><br><br><code>refresh_token</code></td><td>Y</td><td>Provide either Authorization code or refresh_token</td></tr><tr><td><code>grant_type</code></td><td>Y</td><td>Should be "<strong>authorization_code</strong>" or "<strong>refresh_token</strong>".</td></tr><tr><td><code>appkey</code></td><td>Y</td><td>The unique <code>appkey</code> for your App.</td></tr><tr><td><code>appsecret</code></td><td>Y</td><td>The <code>appsecret</code> for your App.</td></tr><tr><td><code>redirect_uri</code></td><td>N</td><td>The token in json will be <mark style="color:green;"><code>POST</code></mark> to <code>redirect_uri</code> if provided.</td></tr></tbody></table>

**Request Example**

```sh
curl -X POST \
--header 'Content-Type: application/x-www-form-urlencoded' \
-d "appkey=1234" \
-d "appsecret=abcd" \
-d "grant_type=authorization_code" \
-d "authorization_code=code" \
-d "redirect_uri=REDIRECT_URL" \
https://$API_BASE_URL/api/account/oauth/token

```

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "code": 0,
    "data": {
        "access_token": "access token",
        "refresh_token": "refresh token",
        "access_token_expires_in": 86400,
        "refresh_token_expires_in": 2592000
    }
}
```

{% endtab %}

{% tab title="Error Code" %}

```
208003: Authorization code expired
```

{% endtab %}
{% endtabs %}

### Get access token without Authorization Code

<mark style="color:green;">`Get`</mark> `/api/account/oauth/authorize`

Get the access token directly from a server-less app.&#x20;

**Parameters**

<table><thead><tr><th width="200">Name</th><th width="128">Mandatory?</th><th>Description</th></tr></thead><tbody><tr><td><code>response_type</code></td><td>Y</td><td>Must be "<strong><code>token</code></strong>" to get an <code>access token.</code></td></tr><tr><td><code>appkey</code></td><td>Y</td><td>The unique <code>appkey</code> for your App.</td></tr><tr><td><code>redirect_uri</code></td><td>Y</td><td>The redirect URL address after authorization success. The <code>access token</code> with be returned to the redirect URL. <br><br>The <code>redirect_uri</code>should be url-encoded. </td></tr><tr><td><code>scope</code></td><td>N</td><td><a href="#grant-scope">Grant Scope</a>. Refer to the definitions for more details. Only grant <code>basic</code> scope if parameter not given.</td></tr><tr><td><code>state</code></td><td>N</td><td>A developer-specified parameter to validate or bring special information. The parameter will be brought to the redirect URL.  </td></tr></tbody></table>

**Returns**

access token which will expire in 1 day.

**Request Example**

```sh
curl https://$API_BASE_URL/api/account/oauth/authorize \
-d "response_type=token" \
-d "appkey=1234" \
-d "redirect_uri=https%3A%2F%2Fmydomain.com%2Fredirect" \
-d "scope=basic" \
-d "state=test" 
```

**Response**

{% tabs %}
{% tab title="200" %}

```json
https://mydomain.com/redirect?access_token=ACCESS_TOKEN&state=test
```

{% endtab %}
{% endtabs %}

### Get User Profiles

<mark style="color:green;">`Get`</mark> `/api/account/party/user`

Get the user profiles under grant scope

**Header**

| Name          | Value                   |
| ------------- | ----------------------- |
| Content-Type  | `application/json`      |
| Authorization | `Bearer <access token>` |

**Request Example**

```sh
curl --location 'https://$API_BASE_URL/api/account/party/user' \
--header 'Authorization: Bearer access_token' 
```

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "code": 0,
    "data": {
        "name": "Nickname",
        "fslUid": 6338505,
        "email": "test@gmail.com",
        "profileImage": "https://xxxx.com/profile.png",
        "walletAddr": {
            "solana": "",
            "evm": ""
        }
    }
}
```

{% endtab %}
{% endtabs %}
