sso

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeserializeStringArray

func DeserializeStringArray(s string) []string

DeserializeStringArray converts a comma-separated string to a string slice

func SerializeStringArray

func SerializeStringArray(arr []string) string

SerializeStringArray converts a string slice to a comma-separated string

Types

type Provider

type Provider interface {
	// GetAuthURL returns the authorization URL for the OAuth2 flow
	GetAuthURL(state string) string

	// ExchangeCode exchanges an authorization code for a token
	ExchangeCode(ctx context.Context, code string) (*oauth2.Token, error)

	// GetUserInfo retrieves user information using the provided token
	GetUserInfo(ctx context.Context, token *oauth2.Token) (*types.UserInfo, error)

	// GetProviderConfig returns the provider configuration
	GetProviderConfig() *config.SSOProviderConfig

	// GetName returns the provider name
	GetName() string

	// GetProtocol returns the protocol (oidc or oauth)
	GetProtocol() string
}

Provider defines the interface that all SSO providers must implement

func CreateProvider

func CreateProvider(cfg *config.SSOProviderConfig, callbackURL string, logger *zap.SugaredLogger) (Provider, error)

CreateProvider creates a provider instance based on the configuration

type Service

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

Service manages SSO authentication using the provider interface pattern

func NewService

func NewService(cfg *config.SSOConfig, logger *zap.SugaredLogger) (*Service, error)

NewService creates a new SSO service with configured providers

func (*Service) CanCreateUser

func (s *Service) CanCreateUser(userInfo *types.UserInfo, providerConfig *config.SSOProviderConfig) bool

CanCreateUser checks if a user can be auto-created based on group membership

func (*Service) ExchangeCode

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

ExchangeCode exchanges an authorization code for a token

func (*Service) GenerateState

func (s *Service) GenerateState() (string, error)

GenerateState is an alias for GenerateStateToken for backward compatibility

func (*Service) GenerateStateToken

func (s *Service) GenerateStateToken() (string, error)

GenerateStateToken generates a secure random state token for OAuth2 flow

func (*Service) GetAuthURL

func (s *Service) GetAuthURL(providerName string, state string) (string, error)

GetAuthURL returns the authorization URL for a given provider

func (*Service) GetEnabledProviders

func (s *Service) GetEnabledProviders() []config.SSOProviderConfig

GetEnabledProviders returns a list of all enabled provider configurations

func (*Service) GetOAuth2Config

func (s *Service) GetOAuth2Config(providerName string) (*oauth2.Config, bool)

GetOAuth2Config returns the OAuth2 config for a provider (for backward compatibility) Returns true if the provider exists

func (*Service) GetProviderConfig

func (s *Service) GetProviderConfig(providerName string) *config.SSOProviderConfig

GetProviderConfig returns the configuration for a specific provider

func (*Service) GetUserInfo

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

GetUserInfo retrieves user information from the provider

func (*Service) IsEnabled

func (s *Service) IsEnabled() bool

IsEnabled returns whether SSO is enabled

func (*Service) MapUserAttributes

func (s *Service) MapUserAttributes(userInfo *types.UserInfo, providerConfig *config.SSOProviderConfig) []string

MapUserAttributes maps user groups to internal user attributes based on provider configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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