This API allows you to generate a new API token for user authentication.
Endpoint Information
Request Method: GET
Request Path: /v2/token/generate
Authorization Required: Yes
Request Headers
X-BH-APIKEY: Your API key.
Query Parameters
timestamp: The current time in milliseconds since the epoch.
signature: The HMAC signature for the request.
Response Structure
The response will include the following fields:
{"code":200,// (number: response code)"msg":"SUCCESS",// (string: message)"data":{// (object: token details)"token":"09ef3523-6242-4a8d-80e2-24cfbdb35851",// (string: generated token)"expireTime":"1740568725231"// (string: timestamp of the expiration time in milliseconds)}}
Signature Generation Process
To generate the signature, follow these steps:
Prepare the Message: Create a string with the current timestamp: "timestamp=1740568725231".
Prepare the Key: Use your API_SECRET as the key.
Generate the Signature: Use HMAC-SHA256 to create a hex string signature from the message and the key.
Example Code for Signature Generation
Python
Java
JavaScript (Node.js)
Go
Rust
Notes
Ensure that you replace "xxxx" with your actual API_SECRET.
The generated token will have an expiration time, which is provided in the response.
use hmac::{Hmac, Mac};
use sha2::Sha256;
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
let api_secret = "xxxx";
let start = SystemTime::now();
let since_the_epoch = start.duration_since(UNIX_EPOCH).expect("Time went backwards");
let message = format!("timestamp={}", since_the_epoch.as_millis());
let signature = generate_hmac(api_secret, &message);
println!("Signature: {}", signature);
}
fn generate_hmac(secret: &str, message: &str) -> String {
let mut mac = Hmac::<Sha256>::new_from_slice(secret.as_bytes()).expect("HMAC can take key of any size");
mac.update(message.as_bytes());
let result = mac.finalize();
hex::encode(result.into_bytes())
}