gcpidentitytoolkit

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 59 Imported by: ? 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.

README

Identity Platform

Parity grade: B · SDK google.golang.org/api@v0.304.0 · last audited 2026-10-29 (185f8a81e)

Coverage

Metric Value
PARITY entries audited 1 (1 ok)
Feature families 6 (4 ok, 2 partial)
Known gaps none
Deferred items 0
Resource leaks unknown

More

Documentation

Index

Constants

View Source
const DefaultPort = 8145

DefaultPort is the dedicated Identity Platform listener's default TCP port (FIREBASE_AUTH_EMULATOR_HOST).

View Source
const DefaultProject = "gopherstack-local"

DefaultProject is the project client calls resolve to when the request names none.

Variables

View Source
var ErrNilAppContext = errors.New("gcpidentitytoolkit: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

View Source
var ErrSnapshotNull = errors.New("gcpidentitytoolkit: snapshot contains a null record")

ErrSnapshotNull is returned when a snapshot holds a null record.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Message string
	Status  string
	HTTP    int
}

APIError is a Google JSON REST error; Message carries the Identity Toolkit error code.

func (*APIError) Error

func (e *APIError) Error() string

Error implements error.

type ConfigProvider

type ConfigProvider interface {
	GetGCPIdentityToolkitSettings() Settings
}

ConfigProvider extracts Identity Platform configuration from the AppContext Config.

type CustomTokenKeys

type CustomTokenKeys func(email string) []*rsa.PublicKey

CustomTokenKeys resolves the public keys that may verify a custom token issued by a service account email.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves the Identity Toolkit and Secure Token REST APIs on a dedicated listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(c *echo.Context) string

ExtractOperation returns the operation name for metrics.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(c *echo.Context) string

ExtractResource returns project[/tenant] for metrics.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the supported operations.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns the Echo handler for every Identity Toolkit and Secure Token request.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset removes all state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Identity Platform runs on its own listener.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the listener.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type IdpSignInResponse

type IdpSignInResponse struct {
	Kind                 string    `json:"kind"`
	FederatedID          string    `json:"federatedId,omitempty"`
	ProviderID           string    `json:"providerId,omitempty"`
	LocalID              string    `json:"localId,omitempty"`
	Email                string    `json:"email,omitempty"`
	OriginalEmail        string    `json:"originalEmail,omitempty"`
	InputEmail           string    `json:"inputEmail,omitempty"`
	DisplayName          string    `json:"displayName,omitempty"`
	FullName             string    `json:"fullName,omitempty"`
	FirstName            string    `json:"firstName,omitempty"`
	LastName             string    `json:"lastName,omitempty"`
	PhotoURL             string    `json:"photoUrl,omitempty"`
	IDToken              string    `json:"idToken,omitempty"`
	RefreshToken         string    `json:"refreshToken,omitempty"`
	ExpiresIn            string    `json:"expiresIn,omitempty"`
	RawUserInfo          string    `json:"rawUserInfo,omitempty"`
	OauthIDToken         string    `json:"oauthIdToken,omitempty"`
	OauthAccessToken     string    `json:"oauthAccessToken,omitempty"`
	TenantID             string    `json:"tenantId,omitempty"`
	MfaPendingCredential string    `json:"mfaPendingCredential,omitempty"`
	VerifiedProvider     []string  `json:"verifiedProvider,omitempty"`
	MfaInfo              []mfaWire `json:"mfaInfo,omitempty"`
	EmailVerified        bool      `json:"emailVerified,omitempty"`
	IsNewUser            bool      `json:"isNewUser,omitempty"`
	NeedConfirmation     bool      `json:"needConfirmation,omitempty"`
}

IdpSignInResponse is the accounts:signInWithIdp response body.

type InMemoryBackend

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

InMemoryBackend holds all Identity Platform state under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend.

func (*InMemoryBackend) AdminCreate

func (b *InMemoryBackend) AdminCreate(c call, r *authRequest) (map[string]any, error)

AdminCreate creates an account without issuing tokens (projects/{p}/accounts).

func (*InMemoryBackend) BatchCreate

func (b *InMemoryBackend) BatchCreate(c call, r *uploadRequest) (map[string]any, error)

BatchCreate imports accounts with optional password hashes (accounts:batchCreate).

func (*InMemoryBackend) BatchDelete

func (b *InMemoryBackend) BatchDelete(c call, ids []string, force bool, tenant string) (map[string]any, error)

BatchDelete deletes accounts; without force only disabled accounts are deleted.

func (*InMemoryBackend) BatchGet

func (b *InMemoryBackend) BatchGet(c call, tenant, token string, maxResults int) (map[string]any, error)

BatchGet pages through accounts with their full password hashes.

func (*InMemoryBackend) ClearAccounts

func (b *InMemoryBackend) ClearAccounts(project, tenant string) error

ClearAccounts deletes every account in a project or tenant (emulator reset endpoint).

func (*InMemoryBackend) CreateAuthURI

func (b *InMemoryBackend) CreateAuthURI(c call, r *authRequest) (map[string]any, error)

CreateAuthURI reports sign-in methods for an identifier, honouring email enumeration protection.

func (*InMemoryBackend) CreateSessionCookie

func (b *InMemoryBackend) CreateSessionCookie(c call, r *authRequest) (map[string]string, error)

CreateSessionCookie mints a session cookie from an ID token.

func (*InMemoryBackend) CreateTenant

CreateTenant creates a tenant with a generated id.

func (*InMemoryBackend) DeleteAccount

func (b *InMemoryBackend) DeleteAccount(c call, r *authRequest) error

DeleteAccount deletes the caller's account (ID token) or any account (admin, by uid).

func (*InMemoryBackend) DeleteTenant

func (b *InMemoryBackend) DeleteTenant(project, id string) error

DeleteTenant removes a tenant and its accounts.

func (*InMemoryBackend) GetConfig

GetConfig returns the project configuration.

func (*InMemoryBackend) GetTenant

GetTenant returns one tenant.

func (*InMemoryBackend) ListTenants

func (b *InMemoryBackend) ListTenants(
	project, token string,
	size int,
) (page.Page[*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant], error)

ListTenants pages through a project's tenants.

func (*InMemoryBackend) Lookup

func (b *InMemoryBackend) Lookup(c call, r *authRequest) (map[string]any, error)

Lookup returns accounts by ID token (client) or by uid, email, phone or provider id (admin).

func (*InMemoryBackend) MfaEnrollmentFinalize

func (b *InMemoryBackend) MfaEnrollmentFinalize(c call, r *finalizeEnrollReq) (*finalizeEnrollRes, error)

MfaEnrollmentFinalize verifies the first code and records the enrollment.

func (*InMemoryBackend) MfaEnrollmentStart

func (b *InMemoryBackend) MfaEnrollmentStart(ctx context.Context, c call, r *startEnrollReq) (*startEnrollResp, error)

MfaEnrollmentStart begins TOTP or SMS second-factor enrollment for a signed-in user.

func (*InMemoryBackend) MfaEnrollmentWithdraw

func (b *InMemoryBackend) MfaEnrollmentWithdraw(c call, r *withdrawReq) (*withdrawResp, error)

MfaEnrollmentWithdraw removes one second factor.

func (*InMemoryBackend) MfaSignInFinalize

func (b *InMemoryBackend) MfaSignInFinalize(c call, r *finalizeSignInReq) (*finalizeSignInRes, error)

MfaSignInFinalize verifies the second factor and issues the session.

func (*InMemoryBackend) MfaSignInStart

func (b *InMemoryBackend) MfaSignInStart(ctx context.Context, c call, r *startSignInReq) (*startSignInResp, error)

MfaSignInStart sends the SMS code of a phone second factor.

func (*InMemoryBackend) OOBCodes

func (b *InMemoryBackend) OOBCodes(project, tenant string) ([]OOBCode, error)

OOBCodes lists the live codes of a project, oldest first. No email is ever sent; tests read codes here.

func (*InMemoryBackend) PasswordPolicy

func (b *InMemoryBackend) PasswordPolicy(
	project, tenant string,
) (*idtkv2.GoogleCloudIdentitytoolkitV2PasswordPolicy, error)

PasswordPolicy implements v2 getPasswordPolicy: the enforced policy of the project or tenant.

func (*InMemoryBackend) ProjectIDs

func (b *InMemoryBackend) ProjectIDs() []string

ProjectIDs lists the project IDs with stored state, always including the default project.

func (*InMemoryBackend) Query

func (b *InMemoryBackend) Query(c call, r *queryRequest) (map[string]any, error)

Query filters, sorts and pages accounts (accounts:query).

func (*InMemoryBackend) RecaptchaConfig

func (b *InMemoryBackend) RecaptchaConfig(
	project, tenant, clientType string,
) (*idtkv2.GoogleCloudIdentitytoolkitV2RecaptchaConfig, error)

RecaptchaConfig implements v2 getRecaptchaConfig for the project or tenant.

func (*InMemoryBackend) Refresh

func (b *InMemoryBackend) Refresh(grantType, token string) (map[string]string, error)

Refresh exchanges a refresh token for a new ID token (securetoken v1/token).

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset removes all state, including signing keys.

func (*InMemoryBackend) ResetPassword

func (b *InMemoryBackend) ResetPassword(c call, r *authRequest) (map[string]any, error)

ResetPassword checks (no newPassword) or applies (newPassword) a password reset code.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads backend state from a snapshot.

func (*InMemoryBackend) SendOobCode

func (b *InMemoryBackend) SendOobCode(ctx context.Context, c call, r *authRequest) (*oobResponse, error)

SendOobCode records a reset, verification or sign-in code; no email is sent.

func (*InMemoryBackend) SendVerificationCode

func (b *InMemoryBackend) SendVerificationCode(ctx context.Context, c call, r *authRequest) (*SessionResponse, error)

SendVerificationCode starts phone sign-in; no SMS is sent and the code is read from the emulator endpoint.

func (*InMemoryBackend) SetAllowExternalBlockingFunctions

func (b *InMemoryBackend) SetAllowExternalBlockingFunctions(allow bool)

SetAllowExternalBlockingFunctions lets blocking functions live on hosts outside loopback.

func (*InMemoryBackend) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time)

SetClock replaces the backend clock.

func (*InMemoryBackend) SetCustomTokenKeys

func (b *InMemoryBackend) SetCustomTokenKeys(f CustomTokenKeys)

SetCustomTokenKeys installs the resolver used to verify RS256 custom tokens.

func (*InMemoryBackend) SetDefaultProject

func (b *InMemoryBackend) SetDefaultProject(id string)

SetDefaultProject sets the project that requests naming none resolve to.

func (*InMemoryBackend) SignInWithCustomToken

func (b *InMemoryBackend) SignInWithCustomToken(c call, r *authRequest) (*tokenResponse, error)

SignInWithCustomToken exchanges a custom token for an ID token, creating the account on first use.

func (b *InMemoryBackend) SignInWithEmailLink(c call, r *authRequest) (*tokenResponse, error)

SignInWithEmailLink completes passwordless sign-in, creating the account on first use.

func (*InMemoryBackend) SignInWithIdp

func (b *InMemoryBackend) SignInWithIdp(c call, r *authRequest) (*IdpSignInResponse, error)

SignInWithIdp exchanges an IdP credential for an Identity Platform session, creating or linking accounts.

func (*InMemoryBackend) SignInWithPassword

func (b *InMemoryBackend) SignInWithPassword(c call, r *authRequest) (*tokenResponse, error)

SignInWithPassword authenticates by email and password.

func (*InMemoryBackend) SignInWithPhoneNumber

func (b *InMemoryBackend) SignInWithPhoneNumber(c call, r *authRequest) (*PhoneSignInResponse, error)

SignInWithPhoneNumber verifies a code (or temporary proof), then signs in, creates or links the account.

func (*InMemoryBackend) SignUp

func (b *InMemoryBackend) SignUp(c call, r *authRequest) (*tokenResponse, error)

SignUp creates an email/password or anonymous account, or links email/password to an anonymous one.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises the backend state, including the token signing key.

func (*InMemoryBackend) Update

func (b *InMemoryBackend) Update(c call, r *authRequest) (*setAccountResponse, error)

Update modifies an account: self-service with an ID token, by oobCode, or by uid for admins.

func (*InMemoryBackend) UpdateConfig

func (b *InMemoryBackend) UpdateConfig(
	project string,
	patch map[string]any,
	mask string,
) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Config, error)

UpdateConfig merges a patch into the project configuration.

func (*InMemoryBackend) UpdateTenant

func (b *InMemoryBackend) UpdateTenant(
	project, id string,
	patch map[string]any,
	mask string,
) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant, error)

UpdateTenant merges a patch into a tenant.

func (*InMemoryBackend) VerificationCodes

func (b *InMemoryBackend) VerificationCodes(project, tenant string) ([]VerificationCode, error)

VerificationCodes lists the live phone verification codes of a project, oldest first.

type OOBCode

type OOBCode struct {
	Email       string `json:"email"`
	OobCode     string `json:"oobCode"`
	OobLink     string `json:"oobLink"`
	RequestType string `json:"requestType"`
}

OOBCode is one stored out-of-band code, as listed by the emulator endpoint.

type PhoneSignInResponse

type PhoneSignInResponse struct {
	LocalID                 string `json:"localId,omitempty"`
	IDToken                 string `json:"idToken,omitempty"`
	RefreshToken            string `json:"refreshToken,omitempty"`
	ExpiresIn               string `json:"expiresIn,omitempty"`
	PhoneNumber             string `json:"phoneNumber"`
	TemporaryProof          string `json:"temporaryProof,omitempty"`
	TemporaryProofExpiresIn string `json:"temporaryProofExpiresIn,omitempty"`
	IsNewUser               bool   `json:"isNewUser,omitempty"`
}

PhoneSignInResponse is the signInWithPhoneNumber response.

type Provider

type Provider struct{}

Provider implements service.Provider for Identity Platform. It serves REST on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type SessionResponse

type SessionResponse struct {
	SessionInfo string `json:"sessionInfo"`
}

SessionResponse is the sendVerificationCode response.

type Settings

type Settings struct {
	DefaultProject string `` //nolint:lll // config struct tags are intentionally verbose
	/* 188-byte string literal not displayed */
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 248-byte string literal not displayed */

	AllowExternalBlockingFunctions bool `` //nolint:lll // config struct tags are intentionally verbose
	/* 295-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI as CLI.GCPIdentityToolkit.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

type VerificationCode

type VerificationCode struct {
	PhoneNumber string `json:"phoneNumber"`
	Code        string `json:"code"`
	SessionInfo string `json:"sessionInfo"`
}

VerificationCode is one live phone verification code, as listed by the emulator endpoint.

Jump to

Keyboard shortcuts

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