githubsso

package
v0.31.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: GPL-3.0 Imports: 10 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 githubsso implements interactive "Sign in with GitHub" login for human dashboard users via the GitHub OAuth web-application flow, and the same identity resolution for a GitHub personal-access token a CLI presents as a bearer. Both paths reduce a GitHub token to a verified Identity and then apply one Allowlist, so the browser and the CLI authorize identically.

It is deliberately independent of internal/githuboidc, which verifies GitHub Actions *workload* identity tokens for CI uploads, not human logins.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAllowed = errors.New("github identity is not on the allowlist")

ErrNotAllowed means authentication succeeded but the account is not on the allowlist. Callers map it to 403, distinct from an authentication failure.

Functions

This section is empty.

Types

type Allowlist

type Allowlist struct {
	Logins map[string]bool
	Emails map[string]bool
	Org    string
	Team   string
}

Allowlist decides which authenticated GitHub accounts may use the instance. An account is permitted if it matches any configured rule: an explicit login or verified email, or membership of Org (further narrowed to Team when set). Logins and Emails keys are compared case-insensitively.

func (Allowlist) Empty

func (a Allowlist) Empty() bool

Empty reports whether no rule is configured — a fail-closed guard for the caller, since an empty allowlist would otherwise permit no one.

func (Allowlist) WantsOrg

func (a Allowlist) WantsOrg() bool

WantsOrg reports whether the allowlist consults org/team membership and so needs the read:org scope. Exported so the server can log/validate config.

type Config

type Config struct {
	ClientID     string
	ClientSecret string
	CallbackURL  string
	Allowlist    Allowlist
	// APIBaseURL overrides https://api.github.com; tests point it at an
	// httptest.Server so identity resolution needs no network.
	APIBaseURL string
}

Config constructs a Provider.

type Identity

type Identity struct {
	Login     string
	Email     string
	AvatarURL string
	UserID    int64
}

Identity is the resolved GitHub account behind a session or bearer token.

type Provider

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

Provider runs the GitHub OAuth web flow and resolves tokens to allowlisted identities.

func New

func New(cfg Config) *Provider

New builds a Provider. The requested scopes are read:user and user:email, plus read:org only when the allowlist gates by org/team.

func (*Provider) AuthCodeURL

func (p *Provider) AuthCodeURL(state string) string

AuthCodeURL is the GitHub authorize URL to redirect the browser to, carrying an opaque state the callback verifies.

func (*Provider) Exchange

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

Exchange trades an authorization code for the caller's identity, applying the allowlist. ErrNotAllowed means the login succeeded but the account is not permitted.

func (*Provider) VerifyToken

func (p *Provider) VerifyToken(ctx context.Context, token string) (Identity, error)

VerifyToken resolves a raw GitHub token (a personal-access token a CLI presents) to an allowlisted identity, or ErrNotAllowed.

Jump to

Keyboard shortcuts

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