# Integration

## Summary

Debank Connect is based on the [OAuth2.0](https://datatracker.ietf.org/doc/html/rfc6749) authorization standard protocol. With DeBank Connect, enable Web3 users to effortlessly sign in your Dapp via DeBank. Once they grant authorization, access their account name/avatar, on-chain portfolio data, and social following data.

## Create App

#### Create and Verify App

Log in to [Official dashboard](https://official.debank.com/), click the Apps tab on the navbar, and click Create New App.

<figure><img src="https://debankglobal.larksuite.com/space/api/box/stream/download/asynccode/?code=OTNhZmQ4YWYzMmRlNzBmZWQxM2MzMWY2NzAwYjAzZTBfVUpoMGRiZG9wNWJkcVdZNUtJbzdzUnRxa05WYWN4aENfVG9rZW46STE2MGJOQXozb3JJTXB4V2dUQnVKYUNDc2RlXzE2OTU5Nzc1NzM6MTY5NTk4MTE3M19WNA" alt=""><figcaption></figcaption></figure>

Once you have finished creating the App, follow the instructions to complete the validation of the App.

<figure><img src="https://1584004705-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LFvONjGHbTb9PuzDLYO%2Fuploads%2Fgit-blob-21d5ce443fc383bd1b93ad759ab784b45063471f%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Create Client

Click "Create Client"

<figure><img src="https://1584004705-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LFvONjGHbTb9PuzDLYO%2Fuploads%2Fgit-blob-470d70317357b5675e90b927e3ad6b843fe91c1f%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

After the creation, save the Client ID and Client Secret for subsequent Integration.

<figure><img src="https://1584004705-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LFvONjGHbTb9PuzDLYO%2Fuploads%2Fgit-blob-16a4927c5de0335a191709df5220d54d9e3a3a52%2Fimage.png?alt=media" alt=""><figcaption></figcaption></figure>

## Integration

{% hint style="info" %}
*DeBank Connect currently only supports OAuth 2.0* [***Authorization Code Grant***](https://datatracker.ietf.org/doc/html/rfc6749#section-4.1)*.*
{% endhint %}

**OAuth 2.0** [**Authorization Code Grant**](https://datatracker.ietf.org/doc/html/rfc6749#section-4.1)**：**

1. The DAPP guides the user to the DeBank Connect authorization page

<figure><img src="https://debankglobal.larksuite.com/space/api/box/stream/download/asynccode/?code=NDhjZjlkMDg0NTQ0MWI1M2M4MDcxOWE2MmEwZDljMmJfY2Zxd1l3d3BWZ24xamVReGU1RVlnV2ZjMXVUSzVsemJfVG9rZW46VjRTaWJqUXlrb2x0WVV4SXBmdXVHQmpZc3BlXzE2OTU5NzgxNzA6MTY5NTk4MTc3MF9WNA" alt=""><figcaption></figcaption></figure>

Example of Authorization Redirect URL:

```
https://debank.com/connect?client_id=7iySAAu5k9zJdpu3NbSyvb6p&response_type=code&scope=user:base:read%20user:chain:read%20user:social:read&redirect_uri=https://example-dapp.com/callback&state=44438279
```

<figure><img src="https://debankglobal.larksuite.com/space/api/box/stream/download/asynccode/?code=Mzc0ZjQ0MDhjY2MwMjhkMWRhMGE2ZjYzYTRhNTZlMTVfMFF4cjhNdnUyNUxlS2lQNEhrZHdCZnc3d3FJWnRFaUhfVG9rZW46VW5SWmJkT0Nzb3NMNGF4Vk1QTnVhZ2d4c1NjXzE2OTU5NzgxOTE6MTY5NTk4MTc5MV9WNA" alt="" width="375"><figcaption></figcaption></figure>

* Description of DeBank Connect Authorization Page URL Parameters

| Paramater      | Requierd     | Description                                                                                                                                                         |
| -------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| client\_id     | Yes          | Third party identification credentials                                                                                                                              |
| redirect\_uri  | Yes          | After the authorization process is complete, it redirects to the dapp with the code.                                                                                |
| scope          | No           | The required scope of access for dApp application.                                                                                                                  |
| response\_type | No           | Authorization code grant mode, default is "code".                                                                                                                   |
| state          | No, Recommed | If this parameter is included in the request, the authentication server will return it exactly as it is during the redirection, in order to prevent replay attacks. |

<table><thead><tr><th>Scope</th><th></th><th data-hidden>Description</th><th data-hidden></th></tr></thead><tbody><tr><td>user:base:read</td><td>User base info</td><td>User Base info</td><td></td></tr><tr><td>user:chain:read</td><td>User on-chain portfolio data</td><td>User on-chain portfolio data</td><td></td></tr><tr><td>user:social:read</td><td>User social info</td><td>User social data</td><td></td></tr></tbody></table>

2. The user can decide whether to authorize the Web service application. If authorization is not agreed, the process terminates. If authorization is agreed, the authorization endpoint is triggered. Then redirect to the "redirect\_uri"

Example of redirect uri:

```
https://example-dapp.com?code=Ro6MIQFigLDcK1hceX9B9B8dgl2ZgcStHXsDQ2XugM0v1gh3&state=132141234
```

| Paramater | Required     | Description                                                                                                                                                         |
| --------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| code      | Yes          | Authorization code. After the user grants authorization, DeBank connect will redirect to the dApp with the code.                                                    |
| state     | No, Recommed | If this parameter is included in the request, the authentication server will return it exactly as it is during the redirection, in order to prevent replay attacks. |

3. The dApp server side obtains access token and refresh token through authorization code.

DeBankConnect API for access token and refresh\_token.

```
URL: https://api.connect.debank.com/oauth/token
Method：POST
Head：auth = HTTPBasicAuth(client_id, client_secret)
Content-Type：form-data
```

{% hint style="info" %}

```
HTTPBasicAuth: https://en.wikipedia.org/wiki/Basic_access_authentication
```

{% endhint %}

| Paramater     | Required | Description                                                                   |
| ------------- | -------- | ----------------------------------------------------------------------------- |
| code          | Yes      | Authorization code                                                            |
| redirect\_uri | Yes      | The link for the redirection when the user is authorized, must be consistent. |
| grant\_type   | Yes      | Authorization code mode, default is "authorization\_code".                    |

Response:

| Paramater      | Required | Description                                       |
| -------------- | -------- | ------------------------------------------------- |
| access\_token  | Yes      | Access Token                                      |
| expires\_in    | Yes      | Expire time                                       |
| refresh\_token | Yes      | Refresh Token                                     |
| scope          | Yes      | The required scope of access for dApp application |
| token\_type    | Yes      | The authentication method for the access token.   |

Example:

```
curl --location -g --request POST 'http://api.connect.debank.com/oauth/token' \
--header 'Authorization: Basic TVM4YUxDemZQTlZDTURiemFHZlZpcUlaOm9iWDJJbFRjdW1XS0U0T1lEYm51RzBGU003Z09wb1I3UFlFUFdlazhJeHJBazlBaQ==' \
--form 'grant_type="authorization_code"' \
--form 'code="<code>"' \
--form 'redirect_uri="<redirect_uri>"'

{
    "access_token": "xmpF421TrBTyBTwYNLAQXE3wTKgqt5h29HaKfGZPJh",
    "expires_in": 864001,
    "refresh_token": "agCd2oYdCrLiqKCJNrOFQmkPg6b7N0OQcPXXw7Pf6vQHNDR2",
    "scope": [
        "user:base:read",
        "user:chain:read",
        "user:social:read"
    ],
    "token_type": "Bearer"
}
```

4. The DAPP service refreshes the access\_token by refresh\_token.

```
URL: api.connect.debank.com/oauth/token
Method：POST
Headers：auth = HTTPBasicAuth(client_id, cleint_secret)
Content-Type：form-data
```

| Paramater      | Required | Description                                           |
| -------------- | -------- | ----------------------------------------------------- |
| refresh\_token | Yes      | Refresh Token                                         |
| grant\_type    | Yes      | Authorization code mode, default is "refresh\_token". |

Response:

| Paramater      | Required | Description                                       |
| -------------- | -------- | ------------------------------------------------- |
| access\_token  | Yes      | Access Token                                      |
| expires\_in    | Yes      | Expire time                                       |
| refresh\_token | Yes      | Refresh Token                                     |
| scope          | Yes      | The required scope of access for dApp application |
| token\_type    | Yes      | The authentication method for the access token.   |

Example:

```
curl --location -g --request POST 'http://api.connect.debank.com/oauth/token' \
--header 'Authorization: Basic UzNNQVdWa1NKZ2FpNHFLVGZPZnR4bEdtOlMwSlI0QThCRUw4T2FENWNjU2xMcVh3TmQzUzJzNFVZVWRSM0VxNkEzczJJZnZTMA==' \
--form 'grant_type="refresh_token"' \
--form 'refresh_token="<refresh_token>"'

{
    "access_token": "xmpF421TrBTyBTwYNLAQXE3wTKgqt5h29HaKfGZPJh",
    "expires_in": 864001,
    "refresh_token": "agCd2oYdCrLiqKCJNrOFQmkPg6b7N0OQcPXXw7Pf6vQHNDR2",
    "scope": [
        "user:base:read",
        "user:chain:read",
        "user:social:read"
    ],
    "token_type": "Bearer"
}
```

## Accessible API list

<table><thead><tr><th>scope</th><th>Link</th><th data-hidden>link</th><th data-hidden></th></tr></thead><tbody><tr><td>user:base:read</td><td><a href="https://docs.cloud.debank.com/en/debank-connect/api/user-base-data">https://docs.cloud.debank.com/en/debank-connect/api/user-base-data</a></td><td></td><td></td></tr><tr><td>user:chain:read</td><td><a href="https://docs.cloud.debank.com/en/debank-connect/api/user-chain-data">https://docs.cloud.debank.com/en/debank-connect/api/user-chain-data</a></td><td></td><td></td></tr><tr><td>user:social:read</td><td><a href="https://docs.cloud.debank.com/en/debank-connect/api/user-social-data">https://docs.cloud.debank.com/en/debank-connect/api/user-social-data</a></td><td></td><td></td></tr></tbody></table>
