Authentication

Authentication can be done in two ways.

API Key

This is the easiest way to authenticate, simply add the x-api-key header with your API Key to your requests.

API Key + JWT Signing

Using JWT adds a degree of complexity but it is strongly recommended to use when you are going to call this API in client-side applications. The JWT Token offers an additional layer of security since it will remain in your source code and will not be sent with requests. You will still need to add the x-api-key to your requests and this time also x-signature. It can be generated as follows:

import (
	"github.com/golang-jwt/jwt/v5"
)

func GenerateSignature(apiKey, jwtKey string) (string, error) {
	claims := jwt.MapClaims{}
	claims["key"] = apiKey
	claims["exp"] = time.Now().Add(time.Second * 15).Unix() // this prevents replay attacks

	token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
	tokenString, err := token.SignedString([]byte(jwtKey))
	if err != nil {
		return "", err
	}

	return tokenString, nil
}

Last updated