oidc

package module
v0.0.0-...-38e17da Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OIDCAuthManager

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

OIDCAuthManager handles authentication using an OIDC provider.

func Init

func Init() *OIDCAuthManager

func NewOIDCAuthManager

func NewOIDCAuthManager(ctx context.Context, config OidcConfig) *OIDCAuthManager

NewOIDCAuthManager initializes and returns a new OIDCAuthManager. The provided context is used for the provider initialization. It returns an error rather than exiting the application.

func (*OIDCAuthManager) AuthCodeURL

func (m *OIDCAuthManager) AuthCodeURL(state string) string

AuthCodeURL returns the URL to which users should be redirected for authentication. The state parameter is used to help mitigate CSRF attacks.

func (*OIDCAuthManager) Authenticate

func (m *OIDCAuthManager) Authenticate(ctx context.Context, token string) (auth.Principal, error)

Authenticate verifies the token, fetches user info, and returns an OidcPrincipal. It decodes the ID token claims and, if present, extracts the roles.

func (*OIDCAuthManager) Exchange

func (m *OIDCAuthManager) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

Exchange exchanges an authorization code for an OAuth2 token.

func (*OIDCAuthManager) GetUserInfo

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

GetUserInfo retrieves the user information from the OIDC provider using the OAuth2 token.

func (*OIDCAuthManager) VerifyIDToken

func (m *OIDCAuthManager) VerifyIDToken(ctx context.Context, rawIDToken string) (*oidc.IDToken, error)

VerifyIDToken verifies the provided raw ID token string and returns the parsed token.

type OidcConfig

type OidcConfig struct {
	ClientID     string `mapstructure:"client_id"`
	ClientSecret string `mapstructure:"client_secret"`
	IssuerURL    string `mapstructure:"issuer_url"`
	RedirectURL  string `mapstructure:"redirect_url"`
}

func LoadConfig

func LoadConfig(configName string, configPaths []string) OidcConfig

type OidcPrincipal

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

OidcPrincipal represents an authenticated user's principal.

func (*OidcPrincipal) GetClaims

func (p *OidcPrincipal) GetClaims() map[string]interface{}

GetClaims returns all claims associated with the principal.

func (*OidcPrincipal) GetEmail

func (p *OidcPrincipal) GetEmail() string

GetEmail returns the principal's email address.

func (*OidcPrincipal) GetID

func (p *OidcPrincipal) GetID() string

GetID returns the principal's unique identifier.

func (*OidcPrincipal) GetRoles

func (p *OidcPrincipal) GetRoles() []string

GetRoles returns the roles assigned to the principal.

Jump to

Keyboard shortcuts

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