Documentation
¶
Overview ¶
Copyright 2018 Portworx
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 Portworx ¶
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 Portworx ¶
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
- Variables
- func GetExpiration(rawtoken string) (time.Time, error)
- func GetIssuedAtTime(rawtoken string) (time.Time, error)
- func IsJwtToken(authstring string) bool
- func ParseToDuration(s string) (time.Duration, error)
- func Token(claims *Claims, signature *Signature, options *Options) (string, error)
- func TokenIssuer(rawtoken string) (string, error)
- func ValidateToken(rawtoken string) error
- type Claims
- type Options
- type Signature
- func NewSignatureECDSA(pem []byte) (*Signature, error)
- func NewSignatureECDSAFromFile(filename string) (*Signature, error)
- func NewSignatureRSA(pem []byte) (*Signature, error)
- func NewSignatureRSAFromFile(filename string) (*Signature, error)
- func NewSignatureSharedSecret(secret string) (*Signature, error)
Constants ¶
const ( // SecondDef is the abbrevation for seconds SecondDef = "s" // MinuteDef is the abbrevation for minutes MinuteDef = "m" // HourDef is the abbrevation for hours HourDef = "h" // DayDef is the abbrevation for days DayDef = "d" // YearDef is the abbrevation for years YearDef = "y" // Day is the duration of hours in a day Day = time.Hour * 24 // Year is the duration of days in a year Year = Day * 365 )
Variables ¶
var ( // SecondRegex is a regular expression for finding seconds as a duration SecondRegex = regexp.MustCompile("^([0-9]+)" + SecondDef + "$") // MinuteRegex is a regular expression for finding minutes as a duration MinuteRegex = regexp.MustCompile("^([0-9]+)" + MinuteDef + "$") // HourRegex is a regular expression for finding hours as a duration HourRegex = regexp.MustCompile("^([0-9]+)" + HourDef + "$") // DayRegex is a regular expression for finding days as a duration DayRegex = regexp.MustCompile("^([0-9]+)" + DayDef + "$") // YearRegex is a regular expression for finding years as a duration YearRegex = regexp.MustCompile("^([0-9]+)" + YearDef + "$") )
Functions ¶
func GetExpiration ¶
This function is similar to jwt-go's (m MapClaims) VerifyExpiresAt Copyright (c) 2012 Dave Grijalva
func GetIssuedAtTime ¶
This function is similar to jwt-go's (m MapClaims) VerifyIssedAt Copyright (c) 2012 Dave Grijalva
func IsJwtToken ¶
IsJwtToken returns true if the provided string is a valid jwt token
func ParseToDuration ¶
ParseToDuration takes in a "human" type duration and changes it to time.Duration. The format for a human type is <number><type>. For example: Five days: 5d; one year: 1y.
func TokenIssuer ¶
TokenIssuer returns the issuer for the raw JWT token.
func ValidateToken ¶
Types ¶
type Claims ¶
type Claims struct { // Issuer is the token issuer. For selfsigned token do not prefix // with `https://`. Issuer string `json:"iss"` // Subject identifier. Unique ID of this account Subject string `json:"sub" yaml:"sub"` // Account name Name string `json:"name" yaml:"name"` // Account email Email string `json:"email" yaml:"email"` // Roles of this account Roles []string `json:"roles,omitempty" yaml:"roles,omitempty"` // (optional) Groups in which this account is part of Groups []string `json:"groups,omitempty" yaml:"groups,omitempty"` }
Claims provides information about the claims in the token See https://openid.net/specs/openid-connect-core-1_0.html#IDToken for more information.
func TokenClaims ¶
TokenClaims returns the claims for the raw JWT token.
type Options ¶
type Options struct { // Expiration time in Unix format as per JWT standard Expiration int64 // Issuer of the claims Issuer string }
Options provide any options to apply to the token
type Signature ¶
type Signature struct { Type jwt.SigningMethod Key interface{} }
Signature describes the signature type using definitions from the jwt package