Skip to Content
Signet

Go API

The public package façade, every Client method, and the exported type groups.

The root signet package is a façade of five files: signet.go (exported aliases), client.go (Client and methods), config.go, errors.go and doc.go. Implementations live in private internal/ packages; aliases may point to any of them. Your code imports only github.com/shakibdshy/signet-auth.

Entry points

SymbolPurpose
New(cfg Config) (*Client, error)Validates config, applies defaults and builds a ready Client.
DefaultConfig() ConfigSecure baseline configuration.
DocsHandler() http.HandlerOptional OpenAPI JSON + Scalar viewer; mount it yourself.
JWKSHandler() http.HandlerOptional JWKS document for asymmetric JWT keys; not mounted by Handler().
UserFromContext(ctx context.Context) (*User, bool)Reads the authenticated User set by RequireAuth/OptionalAuth.

Client methods

MethodPurpose
SignUp(ctx, SignUpInput) (*SignUpResult, error)Create a User and its credential Account.
SignIn(ctx, SignInInput) (*SignInResult, error)Verify a password, rehash if needed, create a Session.
SendMagicLink(ctx, SendMagicLinkInput) errorEmail a single-use magic-link proof.
VerifyMagicLink(ctx, VerifyMagicLinkInput) (*SignInResult, error)Consume a magic-link proof and create a Session.
SendEmailOTP(ctx, SendEmailOTPInput) errorEmail a six-digit sign-in code.
VerifyEmailOTP(ctx, VerifyEmailOTPInput) (*SignInResult, error)Consume a code and create a Session.
SignOut(ctx, SignOutInput) errorRevoke the Session named by the token; unknown tokens are a no-op.
VerifyFreshSession(ctx, string) errorCheck that a Session was authenticated within FreshAge.
RequireFreshSession(http.Handler) http.HandlerMiddleware that rejects stale Sessions with 401.
RequestUserDeletion(ctx, RequestDeleteUserInput) errorIssue a proof to confirm account deletion.
DeleteUser(ctx, ConfirmDeleteUserInput) errorConsume the proof and remove the User and children.
RequestEmailChange(ctx, ChangeEmailInput) errorIssue a single-use proof to a new email address.
VerifyEmailChange(ctx, VerifyEmailChangeInput) errorConsume the proof and commit the new address.
ChangePassword(ctx, ChangePasswordInput) errorVerify the current password, revoke all Sessions and Tokens, then replace the verifier.
SendVerification(ctx, SendVerificationInput) errorIssue an email-verification Token.
VerifyEmail(ctx, VerifyEmailInput) errorConsume a verification Token and mark the User verified.
SendPasswordReset(ctx, SendPasswordResetInput) errorIssue a password-reset Token.
ResetPassword(ctx, ResetPasswordInput) errorConsume a reset Token, revoke Sessions and set a new password.
OAuthStart(ctx, OAuthStartInput) (*OAuthStartResult, error)Begin an OAuth flow and return the authorization URL.
OAuthCallback(ctx, OAuthCallbackInput) (*OAuthCallbackResult, error)Redeem the provider code and return a User or link Token.
LinkOAuthAccount(ctx, LinkOAuthAccountInput) errorConsume a link Token for an authenticated User.
ExchangeToken(ctx, TokenInput) (*TokenPair, error)Exchange credentials or a Refresh token for a TokenPair.
VerifyAccessToken(ctx, raw string) (*User, error)Validate an Access token and load its User.
ListAccounts(ctx, ListAccountsInput) (*ListAccountsResult, error)List safe Account fields for a User.
UnlinkAccount(ctx, UnlinkAccountInput) errorUnlink one guarded Account.
EnableTwoFactor(ctx, EnableTwoFactorInput) (*EnableTwoFactorResult, error)Start TOTP enrollment.
VerifyTwoFactor(ctx, VerifyTwoFactorInput) (*SignInResult, error)Exchange a challenge and code for a Session.
DisableTwoFactor(ctx, DisableTwoFactorInput) errorRemove Second factor enrollment.
RegenerateBackupCodes(ctx, RegenerateBackupCodesInput) (*RegenerateBackupCodesResult, error)Replace all Backup codes.
SetLastMethodCookie(w, method string)Write the signed Last sign-in method cookie.
LastSignInMethod(r *http.Request) stringRead the signed Last sign-in method from a request.
ClearLastSignInMethod(w)Expire the Last sign-in method cookie.
ListSessions(ctx, ListSessionsInput) (*ListSessionsResult, error)List safe Session fields for a User.
RevokeSession(ctx, RevokeSessionInput) errorRevoke one Session; unknown IDs are a no-op.
RevokeAllSessions(ctx, RevokeAllSessionsInput) errorRevoke every Session of a User.
RequireAuth(next http.Handler) http.HandlerMiddleware that requires a valid Session.
OptionalAuth(next http.Handler) http.HandlerMiddleware that attaches a User when one is present.
Handler() http.HandlerThe HTTP endpoint router for mounting under a prefix.

Exported types

  • Models: User, Account, Session, SessionInfo, Token, OAuthIdentity.
  • Contracts: Store, UserStore, AccountStore, SessionStore, TokenStore, Mailer, RateLimiter, Clock, PasswordHasher, EmailTemplates, OAuthProvider.
  • Configuration: Config, CookieConfig, SessionConfig, PasswordConfig, JWTConfig, OAuthConfig.
  • Inputs and results: SignUpInput, SignUpResult, SignInInput, SignInResult, SignOutInput, RequestDeleteUserInput, ConfirmDeleteUserInput, ChangeEmailInput, VerifyEmailChangeInput, ChangePasswordInput, SendVerificationInput, VerifyEmailInput, SendPasswordResetInput, ResetPasswordInput, TokenInput, TokenPair, OAuthStartInput, OAuthStartResult, OAuthCallbackInput, OAuthCallbackResult, LinkOAuthAccountInput, ListSessionsInput, ListSessionsResult, RevokeSessionInput, RevokeAllSessionsInput, TemplateData, Message.
  • Helpers: SystemClock, Argon2idHasher, TokenKind, Version, DefaultTemplates.
  • Errors: exported sentinels such as ErrNotFound, ErrInvalidCredentials, ErrTokenInvalid and ErrRefreshReuse — see Errors.

Token kinds distinguish the single-use proofs: TokenVerifyEmail, TokenResetPassword, TokenOAuthLink, TokenRefresh, TokenOAuthState.

Programmatic vs HTTP

Calling a Client method does not round-trip through HTTP — it runs the same internal service directly with the context.Context you supply. The HTTP endpoints are a separate adapter over those services. Use whichever fits your application; both enforce the same security rules and produce the same effects. See HTTP API and the frontend client for the other surfaces.

Phase 5 methods

Authorization, API keys, organizations and admin management are opt-in. All state lives behind optional application-supplied adapters described in Authorization.

MethodPurpose
Authorize(ctx, userID, resource, action) boolRead-only permission check through the Authorizer.
AuthorizeIn(ctx, userID, orgID, resource, action) boolOrganization-scoped check through AuthorizeIn.
SetRoles(ctx, userID, roles) errorWrite global roles through the RoleWriter.
NewMemoryAuthorizer(statements, roles) AuthorizerBuild an in-memory Authorizer from role statements and a callback.
CreateAPIKey(ctx, CreateAPIKeyInput) (*CreateAPIKeyResult, error)Issue a digest-only key; the raw value is returned once.
VerifyAPIKey(ctx, raw) (*Principal, error)Atomically consume one use and return the key's owner and roles.
ListAPIKeys(ctx, ListAPIKeysInput) (*ListAPIKeysResult, error)List a User's keys.
RevokeAPIKey(ctx, RevokeAPIKeyInput) errorRevoke a User's key.
PrincipalFromContext(ctx) (*Principal, bool)Read the Principal attached by key middleware.
CreateOrganization(ctx, CreateOrganizationInput) (*CreateOrganizationResult, error)Create an Organization.
ListOrganizations(ctx, ListOrganizationsInput) (*ListOrganizationsResult, error)List a User's Organizations.
AddOrganizationMember(ctx, AddOrganizationMemberInput) errorAdd a Member with a role.
ListOrganizationMembers(ctx, orgID, userID, sessionToken) (*ListOrganizationMembersResult, error)List Members.
RemoveOrganizationMember(ctx, orgID, userID, actorID, sessionToken) errorRemove a Member.
SetOrganizationMemberRole(ctx, orgID, userID, role, actorID, sessionToken) errorChange a Member's role.
SetActiveOrganization(ctx, SetActiveOrganizationInput) errorVerify membership before selecting an Active organization.
ActiveOrganizationFromRequest(r) *ActiveOrganizationRead the signed Active organization cookie.
ClearActiveOrganization(w)Expire the Active organization cookie.
AdminListUsers(ctx, AdminListUsersInput) (*AdminListUsersResult, error)List Users for an administrator.
AdminSetUserRole(ctx, AdminSetUserRoleInput) errorWrite global roles for a User.
BanUser(ctx, BanUserInput) errorDisable a User.
UnbanUser(ctx, UnbanUserInput) errorRe-enable a User.
AdminListUserSessions(ctx, actorID, userID, sessionToken) (*ListSessionsResult, error)List a User's Sessions.
AdminRevokeUserSession(ctx, actorID, sessionID, sessionToken) errorRevoke one of a User's Sessions.
ImpersonateUser(ctx, ImpersonateUserInput) (*ImpersonationResult, error)Start a Store-backed impersonation Session.
StopImpersonating(ctx, StopImpersonatingInput) (string, error)Revoke the temp Session and return the original token.
ImpersonationFromRequest(r) (string, string)Read the admin ID and original token from the signed cookie.
SetImpersonationCookie(w, adminID, originalToken)Write the signed impersonation cookie.
ClearImpersonationCookie(w)Expire the impersonation cookie.
IsImpersonating(r) boolReport whether a request carries an impersonation cookie.
AdminActorFromRequest(r, fallback) stringResolve the administrator ID from the cookie.

Phase 5 types

Permission, RoleStatements, Authorizer, AuthorizeIn, RoleWriter, APIKey, APIKeyStore, Principal, CreateAPIKeyInput, CreateAPIKeyResult, ListAPIKeysInput, ListAPIKeysResult, RevokeAPIKeyInput, Organization, OrganizationStore, CreateOrganizationInput, CreateOrganizationResult, ListOrganizationsInput, ListOrganizationsResult, AddOrganizationMemberInput, ListOrganizationMembersInput, ListOrganizationMembersResult, MemberInfo, ActiveOrganization, SetActiveOrganizationInput, AdminUserStore, UserInfo, AdminListUsersInput, AdminListUsersResult, AdminSetUserRoleInput, BanUserInput, UnbanUserInput, ImpersonateUserInput, ImpersonationResult and StopImpersonatingInput.

Passkey methods

MethodPurpose
BeginPasskeyRegistration(ctx, PasskeyRegistrationInput) (*PasskeyCeremonyResult, error)Start enrollment for a signed-in User.
FinishPasskeyRegistration(ctx, PasskeyFinishInput) errorVerify attestation and store the credential.
BeginPasskeySignIn(ctx) (*PasskeyCeremonyResult, error)Start a discoverable sign-in ceremony.
FinishPasskeySignIn(ctx, PasskeyFinishSignInInput) (*SignInResult, error)Verify assertion and create a Session.
ListPasskeys(ctx, PasskeyListInput) (*PasskeyListResult, error)List safe credential fields.
DeletePasskey(ctx, PasskeyDeleteInput) errorRevoke one credential.

Passkey types

PasskeysConfig, PasskeyStore, PasskeyProtocol, WebAuthnCredential, PasskeyInfo, PasskeyRegistrationInput, PasskeyCeremonyResult, PasskeyFinishInput, PasskeySignInInput, PasskeyFinishSignInInput, PasskeyListInput, PasskeyListResult, PasskeyDeleteInput, TokenPasskeyRegistration and TokenPasskeyAuthentication.

Automatic sign-in

MethodPurpose
VerifyEmailAndSignIn(ctx, VerifyEmailInput) (*VerifyEmailAndSignInResult, error)Verify the email and issue a Session when configured.
SignUpResult.SessionTokenAdditive field carrying the Session issued at Sign-up when configured.

Authorization server

MethodPurpose
OAuthAuthorize(ctx, OAuthAuthorizeInput) (*OAuthAuthorizeResult, error)Issue an authorization code with PKCE.
OAuthExchange(ctx, OAuthTokenInput) (*OAuthTokenResult, error)Exchange a code for tokens.
OAuthRefresh(ctx, OAuthTokenInput) (*OAuthTokenResult, error)Rotate a Refresh token.
BeginDeviceAuthorization(ctx, DeviceAuthorizeInput) (*DeviceAuthorizeResult, error)Start device authorization.
ApproveDeviceAuthorization(ctx, DeviceApproveInput) errorApprove a User code.
ExchangeDeviceAuthorization(ctx, string) (*OAuthTokenResult, error)Poll for device tokens.

Types: AuthorizationServerConfig, OAuthClient, OAuthClientStore, DeviceAuthorization, DeviceStore, OAuthScope, OAuthAuthorizeInput, OAuthAuthorizeResult, OAuthTokenInput, OAuthTokenResult, DeviceAuthorizeInput, DeviceAuthorizeResult, DeviceApproveInput.

Organization SSO

MethodPurpose
CreateSSOConnection(ctx, CreateSSOConnectionInput) (*SSOConnectionInfo, error)Store a verified connection.
ListSSOConnections(ctx, string) ([]*SSOConnectionInfo, error)List connections.
DeleteSSOConnection(ctx, string, string) errorDelete a connection.
StartSSOSignIn(ctx, SSOStartInput) (*SSOStartResult, error)Begin an SSO ceremony.
CompleteSSOSignIn(ctx, SSOCallbackInput) (*SSOCallbackResult, error)Verify and create a Session.

SAML SSO

MethodPurpose
StartSAMLSignIn(ctx, SAMLStartInput) (*SAMLStartResult, error)Begin an SP-initiated ceremony.
CompleteSAMLSignIn(ctx, string, *http.Request) (*SAMLACSResult, error)Validate the assertion and create a Session.

SCIM provisioning

SCIMHandler() http.Handler exposes the mounted SCIM server; ValidateSCIMToken(token) error checks a bearer token with ErrSCIMUnauthorized on failure. Types: SCIMConfig, SCIMStore, SCIMGroup, SCIMGroupProjector.

Account controls and operations

MethodPurpose
UpdateUser(ctx, UpdateUserInput) (*UserInfo, error)Change safe profile fields.
SetPassword(ctx, SetPasswordInput) errorAdd a credential Account for a User without one.
VerifyPassword(ctx, VerifyPasswordInput) (bool, error)Server-only password check.
QueryAudit(ctx, string, AuditQueryInput) ([]*AuditEvent, error)Query recorded events.

Types: WindowLimiter, AuditQueryStore, AuditQueryInput, UpdateUserInput, SetPasswordInput, VerifyPasswordInput.

On this page