I get this error 'Error serializing the key. json: error calling 
MarshalJSON for type jws.Claims: unexpected end of JSON input'
I believe that I need to find the function that sign the token. The docs 
don't have any usage exampl 
- https://godoc.org/github.com/SermoDigital/jose/jws

 Any working example would be appreciated. 

Thank you

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "os"
)

import "github.com/SermoDigital/jose/jws"

const (
    privKeyPath = "keys/app.rsa"     // openssl genrsa -out keys/app.rsa 1024
    pubKeyPath  = "keys/app.rsa.pub" // openssl rsa -in keys/app.rsa -pubout > 
keys/app.rsa.pub
)

var signKey []byte

func init() {
    var err error
    signKey, err = ioutil.ReadFile(privKeyPath)
    if err != nil {
        log.Fatal("Error reading private key")
        os.Exit(1)
    }

}

func main() {
    token := createJWT()
    fmt.Println("Created token", token)
}

func createJWT() string {
    claims := jws.Claims{}
    // claims.Set("AccessToken", "level1")
    signMethod := jws.GetSigningMethod("HS512")
    token := jws.NewJWT(claims, signMethod)
    byteToken, err := token.Serialize(signKey)
    if err != nil {
        log.Fatal("Error signing the key. ", err)
        os.Exit(1)
    }

    return string(byteToken)
}

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to