sso

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sso signs people in with an identity provider (OpenID Connect, authorization code flow with PKCE), next to passwords: Google for now.

The ID token comes straight from the provider's token endpoint, over TLS, in exchange for the code: as OpenID Connect allows in that case, its signature is not checked, its claims are (issuer, audience, expiry, nonce).

Index

Constants

This section is empty.

Variables

View Source
var ErrSignIn = errors.New("sign-in failed")

ErrSignIn is a sign-in the provider or its token refused.

Functions

func Configure

func Configure(list ...*Provider)

Configure sets the enabled providers (call at startup).

func RandomString

func RandomString(n int) string

RandomString returns n random bytes, base64url-encoded.

Types

type Identity

type Identity struct {
	Provider      string
	Subject       string
	Email         string
	EmailVerified bool
	Name          string
	// HostedDomain is the Google Workspace domain of the account, if any.
	HostedDomain string
}

Identity is who signed in.

func (Identity) Domain

func (id Identity) Domain() string

Domain returns the domain of the email address.

type Info

type Info struct {
	ID    string `json:"id"`
	Label string `json:"label"`
}

Info is a provider as the login page shows it.

func Enabled

func Enabled() []Info

Enabled lists the enabled providers.

type Provider

type Provider struct {
	ID       string
	Label    string
	AuthURL  string
	TokenURL string
	// Issuers are the accepted "iss" values of ID tokens.
	Issuers      []string
	ClientID     string
	ClientSecret string
	// AllowedDomains: people of these domains get an account on their
	// first sign-in.
	AllowedDomains []string
	// HostedDomain: a domain is the person's only when the provider says
	// so in the "hd" claim (Google Workspace), not from the email alone.
	HostedDomain bool
	DefaultRole  string
	// HTTPClient makes the token request (default http.DefaultClient).
	HTTPClient *http.Client
}

Provider is an OpenID Connect identity provider.

func Get

func Get(id string) (*Provider, bool)

Get returns an enabled provider.

func Google

func Google(clientID, clientSecret string) *Provider

Google returns the Google provider for an OAuth client.

func (*Provider) AuthCodeURL

func (p *Provider) AuthCodeURL(redirectURI, state, nonce, verifier string) string

AuthCodeURL is where to send the browser to sign in.

func (*Provider) DomainAllowed

func (p *Provider) DomainAllowed(id Identity) bool

DomainAllowed reports whether the identity belongs to an allowed domain: its verified email's domain, and for Google, the Workspace domain Google vouches for (a personal account with a matching email is not enough).

func (*Provider) Exchange

func (p *Provider) Exchange(ctx context.Context, redirectURI, code, verifier, nonce string) (*Identity, error)

Exchange trades the code for the person's identity, checking the ID token's issuer, audience, expiry and nonce.

func (*Provider) OwnsEmail

func (p *Provider) OwnsEmail(id Identity) bool

OwnsEmail reports whether the provider vouches that the person holds their email address now. For Google: a Workspace account of the address's domain (hd), or a Gmail address. A consumer Google account created with another address keeps it "verified" even after the address changes hands, so it proves nothing about that address.

Jump to

Keyboard shortcuts

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