Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

How to send JSON Web Token (JWT Token) as header with Postman and golang

func CreateTokenEndpoint(w http.ResponseWriter, req *http.Request) {
    var user User
    _ = json.NewDecoder(req.Body).Decode(&user)
    token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
        "username": user.Username,
    })
    tokenString, error := token.SignedString([]byte("secret"))
    if error != nil {
        fmt.Println(error)
    }
    json.NewEncoder(w).Encode(JwtToken{Token: tokenString})
}
Source by www.thepolyglotdeveloper.com #
 
PREVIOUS NEXT
Tagged: #How #send #JSON #Web #Token #header #Postman #golang
ADD COMMENT
Topic
Name
8+2 =