oauth

package module
v0.0.0-...-f9d256a Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultOAuthConfig

func DefaultOAuthConfig() map[string]*OAuthConfig

DefaultOAuthConfig returns default OAuth configuration

Types

type OAuthConfig

type OAuthConfig struct {
	ClientID     string   `json:"client_id"`
	ClientSecret string   `json:"client_secret"`
	RedirectURL  string   `json:"redirect_url"`
	Scopes       []string `json:"scopes"`
	Provider     string   `json:"provider"` // google, microsoft, github, etc.
}

OAuthConfig holds OAuth provider configuration

type OAuthProvider

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

OAuthProvider implements OAuth2-based authentication

func NewOAuthProvider

func NewOAuthProvider(configs map[string]*OAuthConfig, logger *logrus.Logger) *OAuthProvider

NewOAuthProvider creates a new OAuth provider

func (*OAuthProvider) Authenticate

func (op *OAuthProvider) Authenticate(ctx context.Context, request *types.AuthRequest) (*types.AuthResponse, error)

Authenticate authenticates a user using OAuth

func (*OAuthProvider) Authorize

Authorize authorizes a user

func (*OAuthProvider) CheckPermission

func (op *OAuthProvider) CheckPermission(ctx context.Context, request *types.PermissionRequest) (*types.PermissionResponse, error)

CheckPermission checks if a user has a specific permission

func (*OAuthProvider) Close

func (op *OAuthProvider) Close() error

Close closes the provider

func (*OAuthProvider) Configure

func (op *OAuthProvider) Configure(config map[string]interface{}) error

Configure configures the OAuth provider

func (*OAuthProvider) CreateUserFromOAuth

func (op *OAuthProvider) CreateUserFromOAuth(ctx context.Context, userInfo *OAuthUserInfo) (string, error)

CreateUserFromOAuth creates a user from OAuth user info

func (*OAuthProvider) ExchangeCode

func (op *OAuthProvider) ExchangeCode(ctx context.Context, providerName, code string) (*OAuthTokenResponse, error)

ExchangeCode exchanges authorization code for tokens

func (*OAuthProvider) GetAuthURL

func (op *OAuthProvider) GetAuthURL(ctx context.Context, providerName, state string) (string, error)

GetAuthURL generates authorization URL for OAuth flow

func (*OAuthProvider) GetConnectionInfo

func (op *OAuthProvider) GetConnectionInfo() *types.ConnectionInfo

GetConnectionInfo returns connection information

func (*OAuthProvider) GetName

func (op *OAuthProvider) GetName() string

GetName returns the provider name

func (*OAuthProvider) GetStats

func (op *OAuthProvider) GetStats(ctx context.Context) (*types.AuthStats, error)

GetStats returns provider statistics

func (*OAuthProvider) GetSupportedFeatures

func (op *OAuthProvider) GetSupportedFeatures() []types.AuthFeature

GetSupportedFeatures returns supported features

func (*OAuthProvider) HealthCheck

func (op *OAuthProvider) HealthCheck(ctx context.Context) error

HealthCheck performs health check

func (*OAuthProvider) IsConfigured

func (op *OAuthProvider) IsConfigured() bool

IsConfigured returns whether the provider is configured

func (*OAuthProvider) RefreshOAuthToken

func (op *OAuthProvider) RefreshOAuthToken(ctx context.Context, providerName, refreshToken string) (*OAuthTokenResponse, error)

RefreshOAuthToken refreshes an OAuth token

func (*OAuthProvider) RefreshToken

RefreshToken refreshes an OAuth token

func (*OAuthProvider) RevokeToken

func (op *OAuthProvider) RevokeToken(ctx context.Context, request *types.TokenRevocationRequest) error

RevokeToken revokes an OAuth token

func (*OAuthProvider) ValidateOAuthToken

func (op *OAuthProvider) ValidateOAuthToken(ctx context.Context, providerName, accessToken string) (*OAuthUserInfo, error)

ValidateOAuthToken validates an OAuth token

func (*OAuthProvider) ValidateToken

ValidateToken validates an OAuth token

type OAuthTokenResponse

type OAuthTokenResponse struct {
	AccessToken  string         `json:"access_token"`
	RefreshToken string         `json:"refresh_token,omitempty"`
	ExpiresAt    time.Time      `json:"expires_at"`
	TokenType    string         `json:"token_type"`
	Scope        string         `json:"scope"`
	UserInfo     *OAuthUserInfo `json:"user_info"`
}

OAuthTokenResponse represents OAuth token response

type OAuthUserInfo

type OAuthUserInfo struct {
	ID            string `json:"id"`
	Email         string `json:"email"`
	Name          string `json:"name"`
	FirstName     string `json:"first_name"`
	LastName      string `json:"last_name"`
	Picture       string `json:"picture"`
	VerifiedEmail bool   `json:"verified_email"`
	Provider      string `json:"provider"`
}

OAuthUserInfo represents user information from OAuth provider

Jump to

Keyboard shortcuts

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