Documentation
¶
Overview ¶
Package authkit wires authentication services from one application config. Mount Auth.Handler at Config.BasePath for the built-in net/http routes.
Index ¶
- Variables
- func PrincipalFrom(ctx context.Context) (identity.Principal, bool)
- func SSOProviderName(orgID string) string
- func ValidateManagedSSO(ctx context.Context, manager *ManagedSSO, principal identity.Principal, ...) error
- type Auth
- type Config
- type EmailAndPassword
- type FlowStore
- type ManagedSSO
- type OIDCProvider
- type Plugin
- type SSOConnection
- type SSOConnectionStore
- type SocialProvider
- type Storage
Constants ¶
This section is empty.
Variables ¶
var ErrSSOForbidden = identity.ErrSSOForbidden
var NewManagedSSO = identity.NewManagedSSO
Functions ¶
func SSOProviderName ¶ added in v0.2.0
SSOProviderName returns a stable, URL-safe provider key for an organization. Use the same key when building Config.OrganizationSSO and its callback URL.
func ValidateManagedSSO ¶ added in v0.2.0
func ValidateManagedSSO(ctx context.Context, manager *ManagedSSO, principal identity.Principal, orgID, redirectURL string) error
ValidateManagedSSO discovers the configured OIDC issuer and checks that its client and callback settings can build an AuthKit provider before activation.
Types ¶
type Auth ¶
type Auth struct {
Sessions *identity.SessionService
Password *identity.LoginService
Social *identity.SocialLoginService
TwoFactor *identity.MFAService
Passkeys *gowebauthn.Provider
Organizations identity.OrgStore
Authenticator *identity.Authenticator
// contains filtered or unexported fields
}
Auth owns the configured services and the ready-to-mount HTTP handler.
func (*Auth) Middleware ¶
Middleware resolves authkit's session cookie or a Bearer token and adds the principal to the request context. Authorization remains the handler's job.
func (*Auth) SignInWithIDToken ¶
func (a *Auth) SignInWithIDToken(ctx context.Context, provider, rawIDToken, expectedNonce string) (identity.LoginResult, error)
SignInWithIDToken verifies a native Google, Microsoft, or Apple ID token and returns either an authkit session or a TOTP challenge for the configured user. The app must retain a one-time nonce and pass its expected value here.
type Config ¶
type Config struct {
BaseURL string
BasePath string
Storage Storage
Signer identity.Signer // required for the two-factor plugin
AdminToken string
EmailAndPassword EmailAndPassword
SocialProviders map[string]SocialProvider
OrganizationSSO map[string]OIDCProvider
Plugins []Plugin
}
type EmailAndPassword ¶
type EmailAndPassword struct{ Enabled bool }
type FlowStore ¶
type FlowStore interface {
Put(ctx context.Context, id, kind string, payload []byte, expiresAt time.Time) error
Take(ctx context.Context, id, kind string) (payload []byte, ok bool, err error)
}
FlowStore keeps short-lived, one-time OAuth and passkey challenges. Take must atomically remove the flow so a callback cannot replay it.
type ManagedSSO ¶ added in v0.2.0
type ManagedSSO = identity.ManagedSSO
type OIDCProvider ¶
type OIDCProvider struct {
OrgID string
Domain string // verified email domain; enforced for managed connections
IssuerURL string
ClientID string
ClientSecret string
RedirectURL string
Scopes []string
}
OIDCProvider binds an organization to its own OpenID Connect issuer. OrgID must refer to an existing organization.
type Plugin ¶
type Plugin interface {
// contains filtered or unexported methods
}
Plugin configures an optional authkit feature.
func Organization ¶
func Organization() Plugin
func Passkey ¶
func Passkey(cfg gowebauthn.Config) Plugin
type SSOConnection ¶ added in v0.2.0
type SSOConnection = identity.SSOConnection
Managed SSO is implemented in the identity layer so applications can use it independently of the HTTP adapter.
type SSOConnectionStore ¶ added in v0.2.0
type SSOConnectionStore = identity.SSOConnectionStore
type SocialProvider ¶
type SocialProvider struct {
ClientID string
NativeClientIDs []string
ClientSecret string
RedirectURL string
MicrosoftTenant string
AppleTeamID string
AppleKeyID string
ApplePrivateKey *ecdsa.PrivateKey
}
SocialProvider is the app-level configuration for one provider. RedirectURL defaults to BaseURL + BasePath + "/callback/" + provider name.
type Storage ¶
type Storage struct {
Migrate func(context.Context) error
Flows FlowStore
Users identity.UserStore
Sessions identity.SessionStore
Memberships identity.MembershipStore
SocialAccounts identity.SocialAccountStore
MFA identity.MFAStore
Recovery identity.RecoveryStore
Passkeys identity.WebAuthnCredentialStore
Organizations identity.OrgStore
Teams identity.TeamStore
}
Storage supplies the persistence ports. Postgres returns a complete Storage; applications can supply their own implementations.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package identity is the framework- and storage-agnostic core of authkit: it resolves who a caller is (a Principal) from a credential, and mints/exchanges the credentials machines use.
|
Package identity is the framework- and storage-agnostic core of authkit: it resolves who a caller is (a Principal) from a credential, and mints/exchanges the credentials machines use. |
|
Package social provides OpenID Connect sign-in for Google, Microsoft, LinkedIn, and Apple.
|
Package social provides OpenID Connect sign-in for Google, Microsoft, LinkedIn, and Apple. |
|
store
|
|
|
postgres
Package postgres is authkit's canonical storage adapter: pgx-backed implementations of the identity ports (credentials, users, memberships, sessions) plus the schema.
|
Package postgres is authkit's canonical storage adapter: pgx-backed implementations of the identity ports (credentials, users, memberships, sessions) plus the schema. |
|
token
|
|
|
eddsa
Package eddsa is authkit's default Signer adapter: short-lived EdDSA (Ed25519) JWTs verified by signature only, with a published JWKS.
|
Package eddsa is authkit's default Signer adapter: short-lived EdDSA (Ed25519) JWTs verified by signature only, with a published JWKS. |
|
transport
|
|
|
fiber
Package fiber adapts authkit to gofiber/fiber/v2: a middleware that authenticates the request and carries the Principal in c.Locals.
|
Package fiber adapts authkit to gofiber/fiber/v2: a middleware that authenticates the request and carries the Principal in c.Locals. |
|
nethttp
Package nethttp adapts authkit to the standard net/http server: a middleware that authenticates the request and carries the Principal in the context.
|
Package nethttp adapts authkit to the standard net/http server: a middleware that authenticates the request and carries the Principal in the context. |
|
webauthn
|
|
|
gowebauthn
Package gowebauthn is authkit's WebAuthn (passkey) adapter over github.com/go-webauthn/webauthn.
|
Package gowebauthn is authkit's WebAuthn (passkey) adapter over github.com/go-webauthn/webauthn. |