utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

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

func GenerateNonce() (string, error)

GenerateNonce generates a random base64 encoded string suitable for OpenID nonce

func ParseEnvironment

func ParseEnvironment()

Types

type Cacher

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

func NewDefaultCache(lookup func(string) (interface{}, error), timeout, cleanup time.Duration) (Cacher, error)

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

Jump to

Keyboard shortcuts

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