oauth

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package oauth provides a middleware for authenticating requests.This package provides functionality for token validation and integration with JSON Web Key (JWK) to verify JSON Web Tokens (JWT).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Auth

func Auth(logger log.Logger, options Options) func(inner http.Handler) http.Handler

Auth defines an HTTP middleware for OAuth authentication. It allows access if the token is valid

func LDAPOAuth

func LDAPOAuth(logger log.Logger, ldapOptions *middleware.LDAPOptions, options Options) func(inner http.Handler) http.Handler

LDAPOAuth handles LDAP and OAuth authentication. It grants access based on successful LDAP or OAuth validation

Types

type JWT

type JWT struct {
	// contains filtered or unexported fields
}

JWT represents a JWT token, including its payload, header, and signature.

type JWTContextKey

type JWTContextKey string

type OAuth

type OAuth struct {
	// contains filtered or unexported fields
}

OAuth struct manages OAuth options and caches public keys for JWT validation.

func New

func New(logger log.Logger, options Options) (oAuth *OAuth)

New is a factory function that creates and initializes an oAuth instance

func (*OAuth) Validate

func (o *OAuth) Validate(logger log.Logger, r *http.Request) (*jwt.Token, error)

Validate checks if the token present in header is in jwt format or not. If the format is correct: public key is got from endpoint and RSA to verify if the token is valid.

type Options

type Options struct {
	// Set validity frequency in seconds
	ValidityFrequency int
	JWKPath           string
}

Options defines the validity frequency and JWK path for OAuth authentication.

type PublicKey

type PublicKey struct {
	ID         string   `json:"kid"`
	Alg        string   `json:"alg"`
	Type       string   `json:"kty"`
	Use        string   `json:"use"`
	Operations []string `json:"key_ops"`

	// rsa fields
	Modulus         string `json:"n"`
	PublicExponent  string `json:"e"`
	PrivateExponent string `json:"d"`
	// contains filtered or unexported fields
}

PublicKey encapsulates public key information used for JWT signature validation, including RSA fields.

type PublicKeyCache

type PublicKeyCache struct {
	// contains filtered or unexported fields
}

PublicKeyCache caches public keys for JWT validation and manages concurrency.

type PublicKeys

type PublicKeys struct {
	Keys []PublicKey `json:"keys"`
}

PublicKeys holds a collection of public keys.

func (*PublicKeys) Get

func (publicKeys *PublicKeys) Get(kID string) *PublicKey

Jump to

Keyboard shortcuts

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