For a deeper look into our World Check One API, look into:

Overview |  Quickstart |  Documentation |  Downloads


1 1 1 3

Authorization string on Golang can not be used for WC1 api

I have problem with Golang to generate the correct the correct Authorization string for API access. I try with JS and the string is okay to use while the string from golang can not be used for authentication. Can you help me check what is the different and correct me? Here is my golang code:

func generateSalt(dataToSign string) string {
    token := hmac.New(sha256.New, []byte("secret"))
    macSum := token.Sum(nil)
    return base64.StdEncoding.EncodeToString(macSum)

func main() {
    date = "Wed, 25 May 2022 09:16:45 GMT"
    uri := "groups"
    url := fmt.Sprintf("", uri)
    dataToSign := fmt.Sprintf(`(request-target): get %s%vhost: %s%vdate: %s`, "/v2/groups", "\r\n", "", "\r\n", date)
    log.Printf("dateToSign: %s", dataToSign)
    hmac := generateSalt(dataToSign)
    authorization := fmt.Sprintf(`Signature keyId="%s",algorithm="hmac-sha256",headers="(request-target) host date",signature="%s"`, "api-key", hmac)
    log.Printf("authorization: %s", authorization)

The result from golang is dZzRZfa0yVZsTWof+qEz5VhsFyV83b6DDKXzG9pp/yk=

The code on JS:

function generateAuthHeader(dataToSign){
    var hash = CryptoJS.HmacSHA256(dataToSign,environment["api-secret"]);
    return hash.toString(CryptoJS.enc.Base64); 

var date = "Wed, 25 May 2022 09:16:45 GMT";

var dataToSign = "(request-target): get " + environment["gateway-url"] + "groups\n" +
        "host: " + environment["gateway-host"] + "\n" +
        "date: " + date;
        console.log("date", date)
var hmac = generateAuthHeader(dataToSign);
var authorisation = "Signature keyId=\"" + environment["api-key"] + "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\"" + hmac + "\"";

The result is nx5uyMlq4kOxY1fD5OpoLE6UGI+f5p3OUy+l6G8+oxc=

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

508 1 0 2

Hi @research05,

Thank you for reaching out to us!

With regards to resolving the authorization string with GoLang, we suggest you have a look at our request sample GoLang code via this link (please register with our developer portal):

We encourage you to explore the sample code further as it returns a unique signature string for the said language (GoLang) as well.

A good way to start exploring our API end points is by using the client application Postman. Head to the following link for more rich content and how-to-go about :

Attached a sample print screen of Go + Native snippet code using Postman (in Postman once you have a 200 OK result, on the right vertical bar click on the "</>" to view the returned result).

Also please take note of the JS sample code. A good way to generate a date with GMT would be like this :

var date = new Date().toGMTString();

Please feel free to reach out if you have any further questions.

Best regards,


Code snippet.JPG

Go Native.JPG

code-snippet.jpg (11.2 KiB)
go-native.jpg (60.5 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.