Documentation
¶
Overview ¶
based on https://datatracker.ietf.org/doc/html/rfc7636
Example ¶
Example demonstrating how the JwtVerifier can be configured with a custom Cache function.
package main
import (
"fmt"
"time"
jwtverifier "github.com/okta/okta-jwt-verifier-golang"
"github.com/okta/okta-jwt-verifier-golang/utils"
)
// ForeverCache caches values forever
type ForeverCache struct {
values map[string]interface{}
lookup func(string) (interface{}, error)
}
// Get returns the value for the given key
func (c *ForeverCache) Get(key string) (interface{}, error) {
value, ok := c.values[key]
if ok {
return value, nil
}
value, err := c.lookup(key)
if err != nil {
return nil, err
}
c.values[key] = value
return value, nil
}
// ForeverCache implements the read-only Cacher interface
var _ utils.Cacher = (*ForeverCache)(nil)
// NewForeverCache takes a lookup function and returns a cache
func NewForeverCache(lookup func(string) (interface{}, error), t, c time.Duration) (utils.Cacher, error) {
return &ForeverCache{
values: map[string]interface{}{},
lookup: lookup,
}, nil
}
// Example demonstrating how the JwtVerifier can be configured with a custom Cache function.
func main() {
jwtVerifierSetup := jwtverifier.JwtVerifier{
Cache: NewForeverCache,
// other fields here
}
verifier := jwtVerifierSetup.New()
fmt.Println(verifier)
}
Output:
Index ¶
Examples ¶
Constants ¶
View Source
const ( MinLength = 32 MaxLength = 96 )
Variables ¶
This section is empty.
Functions ¶
func GenerateNonce ¶
GenerateNonce generates a random base64 encoded string suitable for OpenID nonce
func ParseEnvironment ¶
func ParseEnvironment()
Types ¶
type Cacher ¶
Cacher is a read-only cache interface.
Get returns the value associated with the given key.
type PKCECodeVerifier ¶
type PKCECodeVerifier struct {
CodeVerifier string
}
func GenerateCodeVerifier ¶
func GenerateCodeVerifier() (*PKCECodeVerifier, error)
GenerateCodeVerifier generates a code verifier with the minimum length
func GenerateCodeVerifierWithLength ¶
func GenerateCodeVerifierWithLength(length int) (*PKCECodeVerifier, error)
GenerateCodeVerifierWithLength generates a code verifier with the specified length
func (*PKCECodeVerifier) CodeChallengePlain ¶
func (v *PKCECodeVerifier) CodeChallengePlain() string
CodeChallengePlain generates a plain code challenge from a code verifier
func (*PKCECodeVerifier) CodeChallengeS256 ¶
func (v *PKCECodeVerifier) CodeChallengeS256() string
CodeChallengeS256 generates a Sha256 code challenge from a code verifier
func (*PKCECodeVerifier) String ¶
func (v *PKCECodeVerifier) String() string
Click to show internal directories.
Click to hide internal directories.