api

package module
v0.0.0-...-4a6915a Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2015 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Codeship Status for manifest-destiny/api License

api

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// InvalidTokenErr error for an invalid Authorization header value.
	InvalidTokenErr = NewError(http.StatusUnauthorized, "Invalid token")
	// MissingTokenErr error for missing Authorization bearer token.
	MissingTokenErr = NewError(http.StatusBadRequest, "Missing bearer token")
	// InternalServerErr error for any internal server errors.
	InternalServerErr = NewError(http.StatusInternalServerError, "Internal server error")
)

Functions

func BearerToken

func BearerToken(req *restful.Request) (string, error)

BearerToken function returns the bearer token in an Authorization HTTP header.

func WriteError

func WriteError(r *restful.Response, err interface{})

WriteError convenience function for writing error responses.

Types

type Claimer

type Claimer interface {
	Valid() error
}

Claimer represents a set of JWT claims.

type Claims

type Claims struct {
	Validator      *Validator
	Issuer         string    `json:"iss,omitempty"`
	Subject        string    `json:"sub,omitempty"`
	Audience       string    `json:"aud,omitempty"`
	ExpirationTime Timestamp `json:"exp,omitempty"`
	NotBefore      Timestamp `json:"nbf,omitempty"`
	IssuedAt       Timestamp `json:"iat,omitempty"`
	ID             string    `json:"jti,omitempty"`
}

Claims represents a JWT claims set. Includes standard keys with additional Google claims.

func (*Claims) Valid

func (c *Claims) Valid() error

Valid validates a Claims set.

type DB

type DB struct {
	*sqlx.DB
}

DB wrapper for sqlx.DB.

func NewDB

func NewDB(driver, info string) (*DB, error)

NewDB constructor for database connection.

type Error

type Error struct {
	Message string
	// contains filtered or unexported fields
}

Error custom error type.

func NewError

func NewError(code int, msg string) *Error

NewError constructor function for Error.

func (*Error) Error

func (e *Error) Error() string

Error method to satisfy error interface.

type GoogleIdentityClaims

type GoogleIdentityClaims struct {
	*Claims
	Email               string `json:"email,omitempty"`
	EmailVerified       bool   `json:"email_verified,omitempty"`
	Name                string `json:"name,omitempty"`
	GivenName           string `json:"given_name,omitempty"`
	FamilyName          string `json:"family_mame,omitempty"`
	Locale              string `json:"locale,omitempty"`
	Picture             string `json:"picture,omitempty"`
	AuthorizedPresenter string `json:"azp,omitempty"`
	AccessTokenHash     string `json:"at_hash,omitempty"`
}

GoogleIdentityClaims represents Google JWT claims and extends Claims.

type JWSVerifyer

type JWSVerifyer struct {
	*jose.JsonWebKeySet
	// contains filtered or unexported fields
}

JWSVerifyer struct verifies JSON Web Signatures against a JWK Set.

func NewJWSVerifyer

func NewJWSVerifyer(url string) (*JWSVerifyer, error)

NewJWSVerifyer constructs a JWSVerifyer.

func (*JWSVerifyer) UpdateKeySet

func (v *JWSVerifyer) UpdateKeySet() error

UpdateKeySet updates the JWK Set.

func (*JWSVerifyer) Verify

func (v *JWSVerifyer) Verify(token string, c Claimer) error

Verify verifies token against signing key and returns JWT claims.

type Timestamp

type Timestamp struct {
	time.Time
}

Timestamp custom time.Time type with MarshalJSON and UnmarshalJSON methods.

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

MarshalJSON handles Timestamp to byte array conversion.

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON handles JSON timestamp string to Timestamp type.

type TokenValidator

type TokenValidator struct {
	Claims     *Validator
	Signatures *JWSVerifyer
}

TokenValidator convenience container for JWSVerifyer and Claimer.

func GoogleTokenValidator

func GoogleTokenValidator(aud ...string) (*TokenValidator, error)

GoogleTokenValidator constructor for a Google TokenValidator.

type Validator

type Validator struct {
	Issuers        []string
	Subjects       []string
	Audiences      []string
	IDs            []string
	CheckExpired   bool
	CheckNotBefore bool
}

Validator defines Claims keys to validate.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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