Skip to content

401 in REST APIs #11146

Answered by waiphyodev
waiphyodev asked this question in Q&A
Discussion options

You must be logged in to vote

My bad! Thanks for all your helps.

(error) params => get signature for params => encode signature
(success) params => encode params => get signature for encoded params => encode signature

    const params = {
        ...queryParams,    // parameters like command
        apikey: <api-key>,
        response: "json",
    };

    const sortedKeys = Object.keys(params)
        .map((k) => k.toLowerCase())
        .sort();

    const encodedSortedQuery = sortedKeys.map((k) => `${k}=${encodeURIComponent(params[k])}`).join("&");

    const signature = crypto.createHmac("sha1", <secret-key>).update(encodedSortedQuery.toLowerCase()).digest("base64");
    const encodedSignature = encodeURIComponent(…

Replies: 6 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by waiphyodev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #11130 on July 05, 2025 12:57.