Skip to main content

JWT Authentication

Generate JWT token#

  1. Use Chaipay secret key to generate JWT token

  2. Algorithm used for generating token - "HS256"

  3. Payload/claims to encode for generating token

    "iss": "CHAIPAY",
    "sub": "SglffyyZgojEdXWL",
    "iat": 1516239022,
    "exp": 1516239122
    issIssuerDefault Value: "CHAIPAY"
    subSubjectCHAIPay Key
    iatIssued Timestamp in secTimestamp in sec
    expExpiry Timestamp in secTimestamp in sec+100
  1. Add following Headers in request as shown in below request -

    X-Chaipay-Client-Key: Iamport_Client_Key
    Authorization: Bearer token
  2. Sample curl request

    curl --location --request GET '' \
    --header 'X-Chaipay-Client-Key: SglffyyZgojEdXWL' \
    --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJDSEFJUEFZIiwic3ViIjoiY2hhaXBheV9jbGllbnRfaWQiLCJpYXQiOjE1MTYyMzkwMjIsImV4cCI6MTgzMDQwMDMxNn0.CJHQTY-6v5ILILamo13BhVdgK68AIH1oPwXYH4Iyffs' \
    --data-raw ''

Sample code to generate JWT token#

package main
import (
func GenerateToken(jwtKey []byte) string {
cur := time.Now()
expirationTime := cur.Add(100 * time.Second)
// Create the JWT claims, which includes the username and expiry time
claims := jwt.StandardClaims{
// In JWT, the expiry time is expressed as unix milliseconds
Issuer: "CHAIPAY",
Subject: "Chai Client ID",
IssuedAt: cur.Unix(),
ExpiresAt: expirationTime.Unix(),
// Declare the token with the algorithm used for signing, and the claims
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
// Create the JWT string
tokenString, _ := token.SignedString(jwtKey)
return tokenString
func main() {
jwtKey := []byte("my_secret_key")