Documentation ¶
Index ¶
- Variables
- func DecodeSegment(seg string) ([]byte, error)
- func EncodeSegment(seg []byte) string
- func RegisterSigningMethod(alg string, f func() SigningMethod)
- type KeyFunc
- type Parser
- type SigningMethod
- type SigningMethodAES
- func (m *SigningMethodAES) Alg() string
- func (m *SigningMethodAES) Decrypt(encryptedString string, key string, iv string) (string, error)
- func (m *SigningMethodAES) Encrypt(rawString string, key string, iv string) (string, error)
- func (m *SigningMethodAES) Sign(signingString string, key interface{}) (string, error)
- func (m *SigningMethodAES) Verify(signingString, signature string, key interface{}) error
- type Token
Constants ¶
This section is empty.
Variables ¶
var TimeFunc = time.Now
TimeFunc provides the current time when parsing token to validate "exp" claim (expiration time).
Functions ¶
func DecodeSegment ¶
DecodeSegment decodes specific base64url encoding with padding stripped
func EncodeSegment ¶
EncodeSegment encodes specific base64url encoding with padding stripped
func RegisterSigningMethod ¶
func RegisterSigningMethod(alg string, f func() SigningMethod)
RegisterSigningMethod registers the "alg" name and a factory function for signing method. This is typically done during init() in the method's implementation
Types ¶
type KeyFunc ¶
KeyFunc defines the type of function which receives a parsed token and then returns it for validating.
type Parser ¶
type Parser struct { ValidMethods []string // If populated, only these methods will be considered valid UseJSONNumber bool // Use JSON Number format in JSON decoder }
Parser defines configuration values for the Parser instance.
type SigningMethod ¶
type SigningMethod interface { Verify(signingString, signature string, key interface{}) error // Returns nil if signature is valid Sign(signingString string, key interface{}) (string, error) // Returns encoded signature or error Alg() string // Returns the alg identifier for this method (example: 'AES128') }
SigningMethod defines the type of signing used on the token. Implement SigningMethod to add new methods for signing or verifying tokens.
func GetSigningMethod ¶
func GetSigningMethod(alg string) (method SigningMethod)
GetSigningMethod gets a signing method from an "alg" string
type SigningMethodAES ¶
type SigningMethodAES struct {
Name string
}
SigningMethodAES implements the AES family of signing methods
var (
SigningMethodAES128 *SigningMethodAES
)
Specific instances for AES-128 (Rijndael) and any additional AES flavors.
func (*SigningMethodAES) Alg ¶
func (m *SigningMethodAES) Alg() string
Alg returns the signing method name
func (*SigningMethodAES) Decrypt ¶
Decrypt performs AES-128 (Rijndael) decryption on an encrypted string using a provided key and iv.
func (*SigningMethodAES) Encrypt ¶
Encrypt performs AES-128 (Rijndael) decryption on a raw, unencrypted string using a provided key and iv.
func (*SigningMethodAES) Sign ¶
func (m *SigningMethodAES) Sign(signingString string, key interface{}) (string, error)
Sign implements the Encrypt function for this signing method. key must be a map[string]string with indexes "key" and "iv".
func (*SigningMethodAES) Verify ¶
func (m *SigningMethodAES) Verify(signingString, signature string, key interface{}) error
Verify in this case returns nil, because there is no defined way to verify an AES signing method. This is presently included to avoid breaking patterns established by other SigningMethods defined elsewhere. TODO - Define this
type Token ¶
type Token struct { Raw string // The raw token. Populated when you Parse a token Method SigningMethod // The signing method used or to be used Header map[string]interface{} // The first segment of the token Claims map[string]interface{} // The second segment of the token Signature string // The third segment of the token. Populated when you Parse a token Valid bool // Is the token valid? Populated when you Parse/Verify a token }
Token defines the data structure representing a Ninja Encrypted Token.
func Parse ¶
Parse parses, validates, and returns a token. keyFunc will receive the parsed token and should return the key for validating.
func ParseFromRequest ¶
ParseFromRequest will try to find the token in an http.Request. This method will call ParseMultipartForm if there's no token in the header. Currently, it looks in the Authorization header as well as looking for an 'access_token' request parameter in req.Form.
func (*Token) SignedString ¶
SignedString returns the complete, signed token
func (*Token) SigningString ¶
SigningString generates the signing string.