Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add content for Gas Tank API Documentation (XDEFI-6907) #34

Merged
merged 18 commits into from
Jun 12, 2024
Merged
24 changes: 23 additions & 1 deletion .vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,29 @@ function sidebarHome() {
{
text: "⛽ Gas Tank API",
link: "/gas-tank/gas-tank-api",
items: [],
collapsed: true,
items: [
{
text: "🔹 Introduction",
link: "/gas-tank/gas-tank-api",
},
{
text: "🔹 Authentication services",
link: "/gas-tank/gas-tank-api#authentication",
},
{
text: "🔹 Chains services",
link: "/gas-tank/gas-tank-api#chains",
},
{
text: "🔹 Balance & Transactions",
link: "/gas-tank/gas-tank-api#balance-transactions",
},
{
text: "🔹 Other services",
link: "/gas-tank/gas-tank-api#other-services",
},
],
},
{
text: "🛠️ Partners APIs",
Expand Down
111 changes: 111 additions & 0 deletions gas-tank/authentication-services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
## Authentication

### Multiple Address Login

This endpoint facilitates the generation of JWT tokens for multiple wallet addresses in a single request. The request payload should consist of an array of objects, each containing an address and its corresponding signature. Upon successful validation of the signatures, the server will generate JWT tokens for the provided addresses.

::: code-group
HoangVD2 marked this conversation as resolved.
Show resolved Hide resolved

```javascript [Request]
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/login`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: [
{
address: address1, // Address of the user // [!code highlight]
signature: signature1, // Signature // [!code highlight]
},
{
address: address2, // [!code highlight]
signature: signature2, // [!code highlight]
},
...
],
})
.then((response) => {
console.log(response);
// Handle & do something with the response
})
```

```json [Response]
{
"access": "jwt.access.token",
"refresh": "jwt.refresh.token"
}
```

:::

You can also add new wallets to an existing JWT token. Request will be secured by JWT header. Clients need to submit an array of objects containing the address and signature for each new wallet. The server will validate the signatures and, if successful, update the existing JWT token to include the new wallets and generate new JWT.

::: code-group

```javascript [Request]
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/update`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${jwtToken}`, // JWT token // [!code highlight]
},
body: [
{
address: newAddress, // [!code highlight]
signature: newSignature, // [!code highlight]
},
...
],
})
.then((response) => {
console.log(response);
// Handle & do something with the response
})
```

```json [Response]
{
"access": "jwt.access.token",
"refresh": "jwt.refresh.token"
}
```

:::

### Refresh JWT Token

Clients can use this endpoint to obtain a new JWT token without re-authenticating, providing a refresh token.

::: code-group

```javascript [Request]
const GAS_TANK_ENDPOINT = "https://gas-tank.xdefi.services";

await fetch(`${GAS_TANK_ENDPOINT}/v2/auth/refresh`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${jwtToken}`, // JWT token // [!code highlight]
},
body: {
refresh: refreshToken, // Refresh token // [!code highlight]
},
}).then((response) => {
console.log(response);
// Handle & do something with the response
});
```

```json [Response]
{
"access": "jwt.access.token",
"refresh": "jwt.refresh.token"
}
```

:::
Loading
Loading