utils

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: Apache-2.0 Imports: 12 Imported by: 5

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"

	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)) (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

func GenerateNonce() (string, error)

GenerateNonce generates a random base64 encoded string suitable for OpenID nonce

func ParseEnvironment

func ParseEnvironment()

Types

type Cacher added in v1.2.0

type Cacher interface {
	Get(string) (interface{}, error)
}

Cacher is a read-only cache interface.

Get returns the value associated with the given key.

func NewDefaultCache added in v1.2.0

func NewDefaultCache(lookup func(string) (interface{}, error)) (Cacher, error)

NewDefaultCache returns cache with a 5 minute expiration.

type PKCECodeVerifier added in v1.3.0

type PKCECodeVerifier struct {
	CodeVerifier string
}

func GenerateCodeVerifier added in v1.3.0

func GenerateCodeVerifier() (*PKCECodeVerifier, error)

GenerateCodeVerifier generates a code verifier with the minimum length

func GenerateCodeVerifierWithLength added in v1.3.0

func GenerateCodeVerifierWithLength(length int) (*PKCECodeVerifier, error)

GenerateCodeVerifierWithLength generates a code verifier with the specified length

func (*PKCECodeVerifier) CodeChallengePlain added in v1.3.0

func (v *PKCECodeVerifier) CodeChallengePlain() string

CodeChallengePlain generates a plain code challenge from a code verifier

func (*PKCECodeVerifier) CodeChallengeS256 added in v1.3.0

func (v *PKCECodeVerifier) CodeChallengeS256() string

CodeChallengeS256 generates a Sha256 code challenge from a code verifier

func (*PKCECodeVerifier) String added in v1.3.0

func (v *PKCECodeVerifier) String() string

Jump to

Keyboard shortcuts

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