jwt

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: BSD-3-Clause Imports: 7 Imported by: 0

README

JWT

The jwt service type accepts, parses, and validates JSON Web Tokens.

The service settings and available input for the request are as follows:

Name Type Description
token string The raw token
key string The key used to sign the token
signingMethod string The signing method used (HMAC, ECDSA, RSA, RSAPSS)
issuer string The 'iss' standard claim to match against
subject string The 'sub' standard claim to match against
audience string The 'aud' standard claim to match against

The available response outputs are as follows:

Name Type Description
valid boolean If the token is valid or not
token JSON object The parsed token
validationMessage string The validation failure message
error boolean If an error occurred when parsing the token
errorMessage string The error message

The parsed token contents are:

Name Type Description
claims JSON object The set of standard and custom claims provided by the parsed token
signature string The token's signature
signingMethod string The method used to sign the token
header JSON object An object containing header key value pairs for the parsed token

The exp and iat standard claims are automatically validated.

A sample service definition is:

{
  "name": "JWTValidator",
  "description": "Validate a token",
  "ref": "github.com/Iosif02/microgateway/activity/jwt",
  "settings": {
    "signingMethod": "HMAC",
    "key": "qwertyuiopasdfghjklzxcvbnm123456",
    "audience": "www.mashling.io",
    "issuer": "Mashling"
  }
}

An example step that invokes the above JWTValidator service using a token from the header in an HTTP trigger is:

{
  "service": "JWTValidator",
  "input": {
    "token": "=$.payload.headers.Authorization"
  }
}

Utilizing and extracting the response values can be seen in a conditional evaluation:

{"if": "$.JWTValidator.outputs.valid == true"}

or to extract a value from the parsed claims you can use:

=$.jwtService.outputs.token.claims.<custom-claim-key>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

Types

type Activity

type Activity struct{}

func (*Activity) Eval

func (a *Activity) Eval(ctx activity.Context) (done bool, err error)

Eval executes the activity

func (*Activity) Metadata

func (a *Activity) Metadata() *activity.Metadata

Metadata return the metadata for the activity

type Input

type Input struct {
	Token         string `md:"token"`
	Key           string `md:"key"`
	SigningMethod string `md:"signingMethod"`
	Issuer        string `md:"iss"`
	Subject       string `md:"sub"`
	Audience      string `md:"aud"`
}

func (*Input) FromMap

func (r *Input) FromMap(values map[string]interface{}) error

func (*Input) ToMap

func (r *Input) ToMap() map[string]interface{}

type Output

type Output struct {
	Valid             bool        `md:"valid"`
	Token             ParsedToken `md:"token"`
	ValidationMessage string      `md:"validationMessage"`
	Error             bool        `md:"error"`
	ErrorMessage      string      `md:"errorMessage"`
}

func (*Output) FromMap

func (o *Output) FromMap(values map[string]interface{}) error

func (*Output) ToMap

func (o *Output) ToMap() map[string]interface{}

type ParsedToken

type ParsedToken struct {
	Claims        map[string]interface{} `json:"claims"`
	Signature     string                 `json:"signature"`
	SigningMethod string                 `json:"signingMethod"`
	Header        map[string]interface{} `json:"header"`
}

ParsedToken is a parsed JWT token.

type Settings

type Settings struct{}

Directories

Path Synopsis
api

Jump to

Keyboard shortcuts

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