jwts

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

README

JWT

usage

Install

go get github.com/aacfactory/fns-contrib/authorizations/jwts

Use jwt

func dependencies() (v []services.Service) {
    v = []services.Service{
        // add dependencies here
        authorizations.New(authorizations.WithTokenEncoder(jwts.New())),
    }
    return
}

Setup config

authorizations:
  encoder:
    method: "HS256"
    sk: "key"
    issuer: "foo.com"

Supported methods:

  • HS256, HS384, HS512
  • ES256, ES384, ES512
  • PS256, PS384, PS512
  • RS256, RS384, RS512
  • EdDSA

Use Keypair.

authorizations:
  encoder:
    method: "RS512"
    publicKey: "path of key"
    privateKey: "path of key"
    issuer: "foo.com"

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New added in v1.2.1

func New() services.Component

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	Attr map[string]json.RawMessage `json:"attr"`
}

type Config

type Config struct {
	Method     string   `json:"method"`
	SK         string   `json:"sk"`
	PublicKey  string   `json:"publicKey"`
	PrivateKey string   `json:"privateKey"`
	Issuer     string   `json:"issuer"`
	Audience   []string `json:"audience"`
}

func (*Config) CreateJWT

func (config *Config) CreateJWT() (v *JWT, err error)

type JWT

type JWT struct {
	// contains filtered or unexported fields
}

func (*JWT) Parse

func (j *JWT) Parse(signed string) (id string, account string, attributes authorizations.Attributes, valid bool, rc jwt.RegisteredClaims, err error)

func (*JWT) Sign

func (j *JWT) Sign(tid string, account string, attributes authorizations.Attributes, expireAT time.Time) (signed string, err error)

type TokenEncoder added in v1.2.1

type TokenEncoder struct {
	// contains filtered or unexported fields
}

func (*TokenEncoder) Construct added in v1.2.1

func (encoder *TokenEncoder) Construct(options services.Options) (err error)

func (*TokenEncoder) Decode added in v1.2.1

func (encoder *TokenEncoder) Decode(_ context.Context, token authorizations.Token) (result authorizations.Authorization, err error)

func (*TokenEncoder) Encode added in v1.2.1

func (encoder *TokenEncoder) Encode(_ context.Context, param authorizations.Authorization) (token authorizations.Token, err error)

func (*TokenEncoder) Name added in v1.2.1

func (encoder *TokenEncoder) Name() (name string)

func (*TokenEncoder) Shutdown added in v1.2.1

func (encoder *TokenEncoder) Shutdown(_ context.Context)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL