auth

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid username or password")

	// HTTP API errors
	ErrHTTPAPIConnection  = errors.New("failed to connect to authentication API")
	ErrHTTPAPIAuthFailed  = errors.New("authentication API rejected credentials")
	ErrHTTPAPIInvalidResp = errors.New("invalid response from authentication API")
)

Functions

This section is empty.

Types

type APIAuthRequest

type APIAuthRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

APIAuthRequest is the request payload sent to external API

type APIAuthResponse

type APIAuthResponse struct {
	Success  bool   `json:"success"`
	UserID   string `json:"user_id,omitempty"`
	Email    string `json:"email,omitempty"`
	FullName string `json:"full_name,omitempty"`
	Message  string `json:"message,omitempty"`
}

APIAuthResponse is the expected response from external API

type HTTPAPIAuthProvider

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

HTTPAPIAuthProvider handles HTTP API-based authentication

func NewHTTPAPIAuthProvider

func NewHTTPAPIAuthProvider(cfg *config.Config, retryClient *retry.Client) *HTTPAPIAuthProvider

NewHTTPAPIAuthProvider creates a new HTTP API authentication provider

func (*HTTPAPIAuthProvider) Authenticate

func (p *HTTPAPIAuthProvider) Authenticate(
	ctx context.Context,
	username, password string,
) (*Result, error)

Authenticate verifies credentials against external HTTP API

func (*HTTPAPIAuthProvider) Name

func (p *HTTPAPIAuthProvider) Name() string

Name returns provider name for logging

type LocalAuthProvider

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

LocalAuthProvider handles local database authentication

func NewLocalAuthProvider

func NewLocalAuthProvider(s *store.Store) *LocalAuthProvider

NewLocalAuthProvider creates a new local authentication provider

func (*LocalAuthProvider) Authenticate

func (p *LocalAuthProvider) Authenticate(
	ctx context.Context,
	username, password string,
) (*Result, error)

Authenticate verifies credentials against local database

func (*LocalAuthProvider) Name

func (p *LocalAuthProvider) Name() string

Name returns provider name for logging

type OAuthProvider

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

OAuthProvider handles OAuth authentication

func NewGitHubProvider

func NewGitHubProvider(cfg OAuthProviderConfig) *OAuthProvider

NewGitHubProvider creates a new GitHub OAuth provider

func NewGitLabProvider added in v0.16.0

func NewGitLabProvider(cfg OAuthProviderConfig, gitlabURL string) *OAuthProvider

NewGitLabProvider creates a new GitLab OAuth provider. gitlabURL should be the base URL of the GitLab instance (e.g. "https://gitlab.com" or "https://gitlab.example.com" for self-hosted). It defaults to "https://gitlab.com" when empty.

func NewGiteaProvider

func NewGiteaProvider(cfg OAuthProviderConfig, giteaURL string) *OAuthProvider

NewGiteaProvider creates a new Gitea OAuth provider

func NewMicrosoftProvider

func NewMicrosoftProvider(cfg OAuthProviderConfig, tenantID string) *OAuthProvider

NewMicrosoftProvider creates a new Microsoft Entra ID OAuth provider

func (*OAuthProvider) ExchangeCode

func (p *OAuthProvider) ExchangeCode(ctx context.Context, code string) (*oauth2.Token, error)

ExchangeCode exchanges authorization code for access token

func (*OAuthProvider) GetAuthURL

func (p *OAuthProvider) GetAuthURL(state string) string

GetAuthURL returns the OAuth authorization URL

func (*OAuthProvider) GetDisplayName

func (p *OAuthProvider) GetDisplayName() string

GetDisplayName returns the human-readable provider name

func (*OAuthProvider) GetProvider

func (p *OAuthProvider) GetProvider() string

GetProvider returns the provider name

func (*OAuthProvider) GetUserInfo

func (p *OAuthProvider) GetUserInfo(
	ctx context.Context,
	token *oauth2.Token,
) (*OAuthUserInfo, error)

GetUserInfo retrieves user information from the OAuth provider

type OAuthProviderConfig

type OAuthProviderConfig struct {
	ClientID     string
	ClientSecret string
	RedirectURL  string
	Scopes       []string
}

OAuthProviderConfig contains configuration for an OAuth provider

type OAuthUserInfo

type OAuthUserInfo struct {
	ProviderUserID string // Provider's user ID
	Username       string // Provider's username
	Email          string // User email (required)
	FullName       string // User full name
	AvatarURL      string // Avatar URL
}

OAuthUserInfo contains user information from OAuth provider

type Result

type Result = core.AuthResult

Result is a type alias for core.AuthResult. Using an alias (not a new type) keeps all existing *auth.Result references valid without any changes at call sites.

Jump to

Keyboard shortcuts

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