oidc

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package oidc provides OpenID Connect integration for the auth module. It includes functionality for validating OIDC tokens and extracting user information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// IssuerURL is the URL of the OIDC provider
	IssuerURL string

	// ClientID is the client ID for the OIDC provider
	ClientID string

	// ClientSecret is the client secret for the OIDC provider
	ClientSecret string

	// RedirectURL is the redirect URL for the OIDC provider
	RedirectURL string

	// Scopes are the OAuth2 scopes to request
	Scopes []string

	// AdminRoleName is the name of the admin role
	AdminRoleName string

	// Timeout is the timeout for OIDC operations
	Timeout time.Duration

	// RetryConfig is the configuration for retry operations
	RetryConfig RetryConfig
}

Config holds the configuration for OIDC integration.

func DefaultConfig added in v1.5.0

func DefaultConfig() Config

DefaultConfig returns a default configuration for OIDC integration.

type RetryConfig added in v1.2.0

type RetryConfig struct {
	// MaxRetries is the maximum number of retry attempts
	MaxRetries int

	// InitialBackoff is the initial backoff duration
	InitialBackoff time.Duration

	// MaxBackoff is the maximum backoff duration
	MaxBackoff time.Duration

	// BackoffFactor is the factor by which the backoff increases
	BackoffFactor float64
}

RetryConfig holds configuration for retry operations.

func DefaultRetryConfig added in v1.2.0

func DefaultRetryConfig() RetryConfig

DefaultRetryConfig returns the default retry configuration.

type Service

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

Service handles OIDC operations.

func NewService

func NewService(ctx context.Context, config Config, logger *zap.Logger) (*Service, error)

NewService creates a new OIDC service with the provided configuration and logger.

func (*Service) Exchange

func (s *Service) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

Exchange exchanges an authorization code for a token.

func (*Service) GetAuthURL

func (s *Service) GetAuthURL(state string) string

GetAuthURL returns the URL for the OAuth2 authorization endpoint.

func (*Service) GetUserInfo

func (s *Service) GetUserInfo(ctx context.Context, token *oauth2.Token) (*oidc.UserInfo, error)

GetUserInfo gets the user info from the OIDC provider.

func (*Service) IsAdmin

func (s *Service) IsAdmin(roles []string) bool

IsAdmin checks if the user has the admin role.

func (*Service) ValidateToken

func (s *Service) ValidateToken(ctx context.Context, tokenString string) (*jwt.Claims, error)

ValidateToken validates an OIDC token and returns the claims.

Jump to

Keyboard shortcuts

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