-
Notifications
You must be signed in to change notification settings - Fork 24
Add TON Center API v2 auth details page #1494
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| title: "Authentication for API v2" | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| The API v2 requires an API key for all methods, including the JSON-RPC endpoint. | ||
| The key can be sent either in an HTTP header or as a query parameter. | ||
|
|
||
| To obtain an API key, see the [TON Center API key guide](/ecosystem/api/toncenter/get-api-key). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have any expiration limit on the API key? Are there any recommendations to rotate the API key? |
||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a danger reminder of the importance of securely storing the API key. Example: Extra reference: https://docs.stripe.com/keys-best-practices |
||
| | Type | Location | Name | Required | | ||
| | ------- | -------- | ----------- | -------- | | ||
| | API key | Header | `X-API-Key` | Yes | | ||
| | API key | Query | `api_key` | Yes | | ||
|
|
||
| Only one of these is needed per request. | ||
|
|
||
| ## REST endpoints authentication | ||
|
|
||
| ### Header authentication | ||
|
|
||
| Send the API key in the `X-API-Key` header: | ||
|
|
||
| ```bash | ||
| curl "https://<HOST>/api/v2/getMasterchainInfo" \ | ||
| -H "X-API-Key: <API_KEY>" | ||
| ``` | ||
|
|
||
| **Definitions:** | ||
|
|
||
| - `<HOST>` - The base URL of the TON Center API instance (`toncenter.com` for example). | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| - `<API_KEY>` - The API key obtained from the [TON Center bot](https://t.me/toncenter). | ||
|
|
||
| ### Query parameter authentication | ||
|
|
||
| Pass the key as a query parameter named `api_key`: | ||
|
|
||
| ```bash | ||
| curl "https://<HOST>/api/v2/getMasterchainInfo?api_key=<API_KEY>" | ||
| ``` | ||
|
|
||
| Both forms are equivalent. | ||
|
|
||
| ## JSON-RPC endpoints authentication | ||
|
|
||
| Endpoint: `POST /api/v2/jsonRPC` | ||
|
|
||
| The same API key rules apply. Example using header authentication: | ||
|
|
||
| ```bash | ||
| curl "https://<HOST>/api/v2/jsonRPC" \ | ||
| -H "Content-Type: application/json" \ | ||
| -H "X-API-Key: <API_KEY>" \ | ||
| -d '{ | ||
| "jsonrpc": "2.0", | ||
| "id": 1, | ||
| "method": "getMasterchainInfo", | ||
| "params": {} | ||
| }' | ||
| ``` | ||
|
|
||
| Or using the query parameter: | ||
|
|
||
| ```bash | ||
| curl "https://<HOST>/api/v2/jsonRPC?api_key=<API_KEY>" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "jsonrpc": "2.0", | ||
| "id": 1, | ||
| "method": "getMasterchainInfo", | ||
| "params": {} | ||
| }' | ||
| ``` | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we specify the error codes related to API-KEYs here? |
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The requirement of the API key should be specified accurately. An API key is required if the developer desires to make more than one request per second. There is no method that is fully limited by the API Key, just for RPS>1 user will get the HTTP Error 429: