jwt

package
v0.0.0-...-2e0ac8a Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Copyright 2018 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2018 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2018 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenExpired = errors.New("jwt: token expired")
	ErrTokenInvalid = errors.New("jwt: token invalid")
)

Functions

This section is empty.

Types

type Claims

type Claims struct {
	Audience  string `json:"aud,omitempty"`
	ExpiresAt int64  `json:"exp,omitempty"`
	ID        string `json:"jti,omitempty"`
	IssuedAt  int64  `json:"iat,omitempty"`
	Issuer    string `json:"iss,omitempty"`
	NotBefore int64  `json:"nbf,omitempty"`
	Subject   string `json:"sub,omitempty"`
	Scope     string `json:"scp,omitempty"`
	Tenant    string `json:"mender.tenant,omitempty"`
	Device    bool   `json:"mender.device,omitempty"`
}

func (*Claims) Valid

func (c *Claims) Valid() error

Valid checks if claims are valid. Returns error if validation fails. Note that for now we're only using iss, exp, sub, scp. Basic checks are done here, field correctness (e.g. issuer) - at the service level, where this info is available.

type Handler

type Handler interface {
	ToJWT(t *Token) (string, error)
	// FromJWT parses the token and does basic validity checks (Claims.Valid().
	// returns:
	// ErrTokenExpired when the token is valid but expired
	// ErrTokenInvalid when the token is invalid (malformed, missing required claims, etc.)
	FromJWT(string) (*Token, error)
}

Handler jwt generator/verifier

type JWTHandlerRS256

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

JWTHandlerRS256 is an RS256-specific JWTHandler

func NewJWTHandlerRS256

func NewJWTHandlerRS256(privKey *rsa.PrivateKey) *JWTHandlerRS256

func (*JWTHandlerRS256) FromJWT

func (j *JWTHandlerRS256) FromJWT(tokstr string) (*Token, error)

func (*JWTHandlerRS256) ToJWT

func (j *JWTHandlerRS256) ToJWT(token *Token) (string, error)

type SignFunc

type SignFunc func(token *Token) (string, error)

SignFunc will sign and encode token.

type Token

type Token struct {
	Claims Claims
}

Token wrapper

func (*Token) MarshalJWT

func (t *Token) MarshalJWT(sign SignFunc) ([]byte, error)

MarshalJWT marshals Token into JWT comaptible format. `sign` provides means for generating a signed JWT token.

func (*Token) UnmarshalJWT

func (t *Token) UnmarshalJWT(raw []byte, uv UnpackVerifyFunc) error

UnmarshalJWT unmarshals raw JWT data into Token. UnpackVerifyFunc does the actual heavy-lifting of parsing and deserializing base64'ed JWT. Returns an error if `uv` failed, however if `uv` returns a token `t` will be updated as well (may happen if token is valid wrt. to structure & signature, but expired).

type UnpackVerifyFunc

type UnpackVerifyFunc func(s string) (*Token, error)

UnpackVerifyFunc will decode and verify token

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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