sso

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sso manages SSO provider credentials (currently Google OAuth). Credentials live in the `sso_providers` table and are cached in memory after Bootstrap — lookups don't touch the DB. Saving a provider via the admin UI refreshes the cache, so OAuth wiring reflects changes without restarting the server.

The callback URL is never stored. It's derived from configs.Service.AppURL() + "/auth/callback" every time the oauth2 config is built.

Index

Constants

View Source
const CallbackPath = "/auth/callback"

CallbackPath is the relative path the OAuth redirect lands on. Kept as a package constant so the admin UI and login handler agree on the same suffix.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

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

func NewService

func NewService(db *gorm.DB) *Service

func (*Service) AnyEnabled

func (s *Service) AnyEnabled() bool

AnyEnabled reports whether at least one provider has Enabled=true and non-empty credentials. Used by the login page to decide whether to render the "Continue with Google" button.

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context) error

Bootstrap ensures every known provider has at least an empty row and populates the cache. Call once at startup.

func (*Service) Get

func (s *Service) Get(provider string) (entity.SSOProvider, bool)

Get returns the cached row for a provider, or (zero, false) if the provider was never bootstrapped.

func (*Service) IsEmailAllowed added in v0.3.0

func (s *Service) IsEmailAllowed(provider, email string) bool

IsEmailAllowed reports whether an email's domain is permitted to sign in through this provider. Empty AllowedDomains means no restriction. Returns false for malformed emails.

func (*Service) List

func (s *Service) List() []entity.SSOProvider

List returns every provider row, sorted by provider name. Used by the admin UI.

func (*Service) OAuthConfig

func (s *Service) OAuthConfig(provider, appURL string) (*oauth2.Config, bool)

OAuthConfig builds the oauth2.Config for a provider, with the callback URL derived from appURL. Returns (nil, false) if the provider isn't configured or isn't enabled — callers should treat that as "Google login disabled".

func (*Service) Update

func (s *Service) Update(ctx context.Context, provider, clientID, clientSecret string, enabled bool, allowedDomains string) error

Update writes new credentials for a provider and refreshes the cache. allowedDomains is a comma-separated list of email domains; empty string disables the restriction.

Jump to

Keyboard shortcuts

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