authn

package
v0.1.29 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 12 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 authn is api's port to the sign-in service. It verifies an ID token of Firebase Auth with its revocation and names the class of a refusal, removes a user and lists the users (R03, R20, R21, R32). api's code holds the Port: Firebase is its adapter on the Admin SDK for Go, and authntest a fake of it for the tests of the rest. The sign-in service's UID lives only in the account's row; rights are the account's (R04), so another sign-in service changes the adapter, not the rights or the data.

Index

Constants

View Source
const FreshFor = 300 * time.Second

FreshFor is how old a sign-in may be, and how far ahead of api's clock, for an action that waits for a fresh one: the deletion of a profile or of an account, and a forgotten PIN's change (R20). A refusal for want of one carries it, as RFC 9470 carries max_age.

Variables

This section is empty.

Functions

func Fresh

func Fresh(authTime, now time.Time) bool

Fresh says whether a sign-in at authTime is fresh at now: no older than FreshFor, and no further ahead than FreshFor either, the leeway the Admin SDK gives a token's own times. A token with no time of sign-in is not fresh.

Types

type Class

type Class int

Class is why a token was refused (R20; architecture 3.10).

const (
	// Expired is a token past its time: the SDK on the device refreshes it.
	Expired Class = iota + 1
	// Invalid is a token that is not one: malformed, of another project, or
	// signed by no key of Google's.
	Invalid
	// Revoked is a token issued before the user's tokens were revoked.
	Revoked
	// NoUser is a token whose user the sign-in service no longer has.
	NoUser
	// Disabled is a token whose user is disabled.
	Disabled
	// Failed is a check that did not finish: Google's keys, the network, the
	// service. It says nothing of the token.
	Failed
)

The classes of a refusal.

func (Class) String

func (c Class) String() string

String is the class's name.

type Firebase

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

Firebase is the Port on Firebase Auth, through the Admin SDK for Go (R03).

func New

func New(ctx context.Context, o Options) (*Firebase, error)

New builds the adapter. It makes no call: Google's keys come with the first token, and the service's token with the first call that needs it.

func (*Firebase) RemoveUser

func (f *Firebase) RemoveUser(ctx context.Context, uid string) error

RemoveUser revokes the user's refresh tokens and deletes the user. The deletion goes on when the revocation fails, since a deleted user's refresh token serves nobody, and the step is done once the deletion is (R21).

func (*Firebase) Users

func (f *Firebase) Users(ctx context.Context) iter.Seq2[User, error]

Users lists the users a page at a time, as the sign-in service gives them.

func (*Firebase) Verify

func (f *Firebase) Verify(ctx context.Context, idToken string) (Token, error)

Verify verifies the token's signature and asks the sign-in service whether it is revoked and its user still there and enabled. A token revoked, or of a user who is not there, is read once more by its signature alone, with no call, for its UID (R20).

type Options

type Options struct {
	// ProjectID is the Firebase project whose tokens api accepts.
	ProjectID string
	// Credentials is the JSON of a service account's key, and only of a service
	// account, off a deployment. Empty is the token of the service's own account
	// from the metadata server, as on Cloud Run, with no key: never the
	// credentials the machine has by default, which may be gcloud's, of a user
	// and another project.
	Credentials []byte
}

Options are what the adapter of Firebase Auth is built from (R32).

type Port

type Port interface {
	// Verify verifies an ID token with its revocation. A refused token is a
	// *Refusal, which names its class.
	Verify(ctx context.Context, idToken string) (Token, error)
	// RemoveUser revokes the user's refresh tokens, then deletes the user: step 3
	// of an account's deletion (R21). A user who is not there is a step already
	// done, and no error.
	RemoveUser(ctx context.Context, uid string) error
	// Users lists every user of the sign-in service, for the operator's job that
	// removes those without an account (R21). An error ends the list.
	Users(ctx context.Context) iter.Seq2[User, error]
}

Port is what api asks of the sign-in service.

type Refusal

type Refusal struct {
	// Class is why the token was refused.
	Class Class
	// UID is the token's user, read from its signature alone, when the class is
	// Revoked or NoUser: api answers those by the account's mark (R20).
	UID string
	// contains filtered or unexported fields
}

Refusal is a token that Verify refused, by its class. Its text is the class alone: the SDK's words name the UID, and a token or a UID is not for a log or a reply. The SDK's error is its link, for the log to name by its type.

func (*Refusal) Error

func (r *Refusal) Error() string

Error is the refusal's class.

func (*Refusal) Unwrap

func (r *Refusal) Unwrap() error

Unwrap is the SDK's error.

type Token

type Token struct {
	// UID is the sign-in service's ID of the user.
	UID string
	// AuthTime is when the user signed in, not when the token was refreshed.
	AuthTime time.Time
}

Token is what api reads of a verified ID token: the user and when they signed in. Neither the email nor any other claim is read (R29 canvas-api).

type User

type User struct {
	// UID is the sign-in service's ID of the user.
	UID string
	// LastSignIn is when the user last signed in; zero if never.
	LastSignIn time.Time
	// LastRefresh is when the user's ID token was last refreshed; zero if never.
	LastRefresh time.Time
	// Created is when the user was made, so that one made and never signed in is
	// not taken for one long gone.
	Created time.Time
}

User is what api reads of a user of the sign-in service.

Directories

Path Synopsis
Package authntest is a fake of authn.Port for the tests of the code that holds it: a token is whatever the test says it is, and the users are the test's own.
Package authntest is a fake of authn.Port for the tests of the code that holds it: a token is whatever the test says it is, and the users are the test's own.

Jump to

Keyboard shortcuts

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