oauth2: golang.org/x/oauth2/jws Index | Files

package jws

import "golang.org/x/oauth2/jws"

Package jws provides a partial implementation of JSON Web Signature encoding and decoding. It exists to support the golang.org/x/oauth2 package.

See RFC 7515.

Deprecated: this package is not intended for public use and might be removed in the future. It exists for internal use only. Please switch to another JWS package or copy this package into your own source tree.

Index

Package Files

jws.go

func Encode Uses

func Encode(header *Header, c *ClaimSet, key *rsa.PrivateKey) (string, error)

Encode encodes a signed JWS with provided header and claim set. This invokes EncodeWithSigner using crypto/rsa.SignPKCS1v15 with the given RSA private key.

func EncodeWithSigner Uses

func EncodeWithSigner(header *Header, c *ClaimSet, sg Signer) (string, error)

EncodeWithSigner encodes a header and claim set with the provided signer.

func Verify Uses

func Verify(token string, key *rsa.PublicKey) error

Verify tests whether the provided JWT token's signature was produced by the private key associated with the supplied public key.

type ClaimSet Uses

type ClaimSet struct {
    Iss   string `json:"iss"`             // email address of the client_id of the application making the access token request
    Scope string `json:"scope,omitempty"` // space-delimited list of the permissions the application requests
    Aud   string `json:"aud"`             // descriptor of the intended target of the assertion (Optional).
    Exp   int64  `json:"exp"`             // the expiration time of the assertion (seconds since Unix epoch)
    Iat   int64  `json:"iat"`             // the time the assertion was issued (seconds since Unix epoch)
    Typ   string `json:"typ,omitempty"`   // token type (Optional).

    // Email for which the application is requesting delegated access (Optional).
    Sub string `json:"sub,omitempty"`

    // The old name of Sub. Client keeps setting Prn to be
    // complaint with legacy OAuth 2.0 providers. (Optional)
    Prn string `json:"prn,omitempty"`

    // See http://tools.ietf.org/html/draft-jones-json-web-token-10#section-4.3
    // This array is marshalled using custom code (see (c *ClaimSet) encode()).
    PrivateClaims map[string]interface{} `json:"-"`
}

ClaimSet contains information about the JWT signature including the permissions being requested (scopes), the target of the token, the issuer, the time the token was issued, and the lifetime of the token.

func Decode Uses

func Decode(payload string) (*ClaimSet, error)

Decode decodes a claim set from a JWS payload.

type Header struct {
    // The algorithm used for signature.
    Algorithm string `json:"alg"`

    // Represents the token type.
    Typ string `json:"typ"`

    // The optional hint of which key is being used.
    KeyID string `json:"kid,omitempty"`
}

Header represents the header for the signed JWS payloads.

type Signer Uses

type Signer func(data []byte) (sig []byte, err error)

Signer returns a signature for the given data.

Package jws imports 11 packages (graph) and is imported by 24 packages. Updated 2017-07-20. Refresh now. Tools for package owners.