Skip to content

Commit

Permalink
docs: update content for Gas Tank API Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
HoangVD2 committed Apr 11, 2024
1 parent 9736c63 commit deacc12
Show file tree
Hide file tree
Showing 7 changed files with 934 additions and 324 deletions.
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
11 changes: 0 additions & 11 deletions components/gas-tank/AutLogin.jsx

This file was deleted.

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

```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

0 comments on commit deacc12

Please sign in to comment.