Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type ConfigProvider
- type CustomTokenKeys
- type Handler
- func (h *Handler) Addr() string
- func (h *Handler) ExtractOperation(c *echo.Context) string
- func (h *Handler) ExtractResource(c *echo.Context) string
- func (h *Handler) GetSupportedOperations() []string
- func (h *Handler) Handler() echo.HandlerFunc
- func (h *Handler) MatchPriority() int
- func (h *Handler) Name() string
- func (h *Handler) Reset()
- func (h *Handler) Restore(ctx context.Context, data []byte) error
- func (h *Handler) RouteMatcher() service.Matcher
- func (h *Handler) Shutdown(ctx context.Context)
- func (h *Handler) Snapshot(ctx context.Context) []byte
- func (h *Handler) StartWorker(ctx context.Context) error
- type IdpSignInResponse
- type InMemoryBackend
- func (b *InMemoryBackend) AdminCreate(c call, r *authRequest) (map[string]any, error)
- func (b *InMemoryBackend) BatchCreate(c call, r *uploadRequest) (map[string]any, error)
- func (b *InMemoryBackend) BatchDelete(c call, ids []string, force bool, tenant string) (map[string]any, error)
- func (b *InMemoryBackend) BatchGet(c call, tenant, token string, maxResults int) (map[string]any, error)
- func (b *InMemoryBackend) ClearAccounts(project, tenant string) error
- func (b *InMemoryBackend) CreateAuthURI(c call, r *authRequest) (map[string]any, error)
- func (b *InMemoryBackend) CreateSessionCookie(c call, r *authRequest) (map[string]string, error)
- func (b *InMemoryBackend) CreateTenant(project string, in *idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant, error)
- func (b *InMemoryBackend) DeleteAccount(c call, r *authRequest) error
- func (b *InMemoryBackend) DeleteTenant(project, id string) error
- func (b *InMemoryBackend) GetConfig(project string) *idtkv2.GoogleCloudIdentitytoolkitAdminV2Config
- func (b *InMemoryBackend) GetTenant(project, id string) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant, error)
- func (b *InMemoryBackend) ListTenants(project, token string, size int) (page.Page[*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant], error)
- func (b *InMemoryBackend) Lookup(c call, r *authRequest) (map[string]any, error)
- func (b *InMemoryBackend) MfaEnrollmentFinalize(c call, r *finalizeEnrollReq) (*finalizeEnrollRes, error)
- func (b *InMemoryBackend) MfaEnrollmentStart(ctx context.Context, c call, r *startEnrollReq) (*startEnrollResp, error)
- func (b *InMemoryBackend) MfaEnrollmentWithdraw(c call, r *withdrawReq) (*withdrawResp, error)
- func (b *InMemoryBackend) MfaSignInFinalize(c call, r *finalizeSignInReq) (*finalizeSignInRes, error)
- func (b *InMemoryBackend) MfaSignInStart(ctx context.Context, c call, r *startSignInReq) (*startSignInResp, error)
- func (b *InMemoryBackend) OOBCodes(project, tenant string) ([]OOBCode, error)
- func (b *InMemoryBackend) PasswordPolicy(project, tenant string) (*idtkv2.GoogleCloudIdentitytoolkitV2PasswordPolicy, error)
- func (b *InMemoryBackend) ProjectIDs() []string
- func (b *InMemoryBackend) Query(c call, r *queryRequest) (map[string]any, error)
- func (b *InMemoryBackend) RecaptchaConfig(project, tenant, clientType string) (*idtkv2.GoogleCloudIdentitytoolkitV2RecaptchaConfig, error)
- func (b *InMemoryBackend) Refresh(grantType, token string) (map[string]string, error)
- func (b *InMemoryBackend) Reset()
- func (b *InMemoryBackend) ResetPassword(c call, r *authRequest) (map[string]any, error)
- func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error
- func (b *InMemoryBackend) SendOobCode(ctx context.Context, c call, r *authRequest) (*oobResponse, error)
- func (b *InMemoryBackend) SendVerificationCode(ctx context.Context, c call, r *authRequest) (*SessionResponse, error)
- func (b *InMemoryBackend) SetAllowExternalBlockingFunctions(allow bool)
- func (b *InMemoryBackend) SetClock(now func() time.Time)
- func (b *InMemoryBackend) SetCustomTokenKeys(f CustomTokenKeys)
- func (b *InMemoryBackend) SetDefaultProject(id string)
- func (b *InMemoryBackend) SignInWithCustomToken(c call, r *authRequest) (*tokenResponse, error)
- func (b *InMemoryBackend) SignInWithEmailLink(c call, r *authRequest) (*tokenResponse, error)
- func (b *InMemoryBackend) SignInWithIdp(c call, r *authRequest) (*IdpSignInResponse, error)
- func (b *InMemoryBackend) SignInWithPassword(c call, r *authRequest) (*tokenResponse, error)
- func (b *InMemoryBackend) SignInWithPhoneNumber(c call, r *authRequest) (*PhoneSignInResponse, error)
- func (b *InMemoryBackend) SignUp(c call, r *authRequest) (*tokenResponse, error)
- func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte
- func (b *InMemoryBackend) Update(c call, r *authRequest) (*setAccountResponse, error)
- func (b *InMemoryBackend) UpdateConfig(project string, patch map[string]any, mask string) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Config, error)
- func (b *InMemoryBackend) UpdateTenant(project, id string, patch map[string]any, mask string) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant, error)
- func (b *InMemoryBackend) VerificationCodes(project, tenant string) ([]VerificationCode, error)
- type OOBCode
- type PhoneSignInResponse
- type Provider
- type SessionResponse
- type Settings
- type VerificationCode
Constants ¶
const DefaultPort = 8145
DefaultPort is the dedicated Identity Platform listener's default TCP port (FIREBASE_AUTH_EMULATOR_HOST).
const DefaultProject = "gopherstack-local"
DefaultProject is the project client calls resolve to when the request names none.
Variables ¶
var ErrNilAppContext = errors.New("gcpidentitytoolkit: nil app context")
ErrNilAppContext is returned when Init is called with a nil AppContext.
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 ¶
APIError is a Google JSON REST error; Message carries the Identity Toolkit error code.
type ConfigProvider ¶
type ConfigProvider interface {
GetGCPIdentityToolkitSettings() Settings
}
ConfigProvider extracts Identity Platform configuration from the AppContext Config.
type CustomTokenKeys ¶
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) ExtractOperation ¶
ExtractOperation returns the operation name for metrics.
func (*Handler) ExtractResource ¶
ExtractResource returns project[/tenant] for metrics.
func (*Handler) GetSupportedOperations ¶
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 ¶
MatchPriority is irrelevant because RouteMatcher never matches.
func (*Handler) RouteMatcher ¶
RouteMatcher never matches: Identity Platform runs on its own listener.
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 ¶
func (b *InMemoryBackend) CreateTenant( project string, in *idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant, ) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant, error)
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 ¶
func (b *InMemoryBackend) GetConfig(project string) *idtkv2.GoogleCloudIdentitytoolkitAdminV2Config
GetConfig returns the project configuration.
func (*InMemoryBackend) GetTenant ¶
func (b *InMemoryBackend) GetTenant(project, id string) (*idtkv2.GoogleCloudIdentitytoolkitAdminV2Tenant, error)
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 (*InMemoryBackend) SignInWithEmailLink ¶
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 ¶
func (p *Provider) Init(ctx *service.AppContext) (service.Registerable, error)
Init creates the backend and handler; the port is bound in StartWorker.
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.