Skip to content

Golang JSON Web Token builder with easy to use API for JWS and nested JWT (JWS+JWE)

License

Notifications You must be signed in to change notification settings

bwplotka/go-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-jwt JWT Compatible

Build Status Go Report Card Golang JSON Web Token builder with easy to use API for JWS and nested JWT (JWS+JWE)

It wraps and is inspired by gopkg.in/square/go-jose.v2 (especially jwt subpackage)

NOTE: Please, make sure you get fixed version of go-jose.v2. square/go-jose#142

Usage:

package main

import (
    "fmt"
    "github.com/Bplotka/go-jwt"
)

func main() {
    p := "some_payload"
    cl := jwt.Claims{
        // Your standard claims here...
    }
    
    b, err := jwt.NewDefaultBuilder() // or jwt.NewBuilder(rsaPrvKey, signAlg, keyAlg, contentAlg)
    if err != nil {
        // Handle error here...
    }
    
    token, err := b.SignedAndEncryptedJWT().
        Claims(cl).
        Payload(p).
        CompactSerialize()
    if err != nil {
        // Handle error here...
    }
    
    // Generated valid nested JWT in `token` variable!
    // (....)
    // Let's revert the process:
     
    obtainer := b.FromSignedAndEncryptedJWT(token)
    
    var fetched string
    err = obtainer.Payload(&fetched)
    if err != nil {
        // Handle error here..
    }
    
    // We have "some_payload" again in `fetched` variable.
    
    fetchedStdClaims, err := obtainer.StdClaims()
    if err != nil {
        // Handle error here..
    }
    
    // We have our standard claims again in `fetchedStdClaims` variable.
    fmt.Println(fetchedStdClaims.Issuer)
    fmt.Println(fetchedStdClaims.Subject)
    // ...
}

About

Golang JSON Web Token builder with easy to use API for JWS and nested JWT (JWS+JWE)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages