Skip to content

API Reference

Service Provider

ClassDescription
CoreSpJwtAuthServiceProviderRegisters the sp-jwt guard, middleware aliases, commands, migrations, routes, and container bindings

Services (Main Entry Points)

ServiceDescription
JwtTokenServiceIssue, validate, rotate, and revoke first-party JWT token pairs
MfaChallengeBrokerCreate MFA challenges that store pending token context
OtpChallengeBrokerCreate hashed OTP codes, verify, check expiry and lockout
EmailVerificationBrokerCreate and verify one-time email verification tokens
PasswordResetBrokerCreate, verify, and consume one-time password reset tokens
ApiKeyServiceCreate, validate, rotate, and revoke scoped API keys
ExternalIdentityStoreStore normalized provider identity records
OAuthServerServiceAuthorization requests, token grants, revocation, introspection
OAuthClientRepositoryRegister and manage OAuth clients
OAuthConsentRepositoryStore and revoke user consents
OAuthScopeRepositoryValidate allowed OAuth scopes

Contracts (Bind in Container for App-Owned Delivery)

ContractBind when using
OtpChannelSenderOTP delivery (email, SMS, etc.)
EmailVerificationSenderEmail verification notification delivery
PasswordResetSenderPassword reset notification delivery
ExternalIdentityProviderCustom Socialite/OIDC provider adapter
TokenContextValidatorPre-issue token context validation hook

Key DTOs

DTOPurpose
TokenContextScopes, claims, subject, device, session for token issue
TokenSubjectType/id pair embedded in tokens (e.g. tenant, user)
TokenPairAccess + refresh token response
OtpDestinationChannel, normalized destination, masked destination
ApiKeyContextOwner, scopes, claims, IPs for API key creation
ApiKeyPrincipalAuthenticated API key identity
ExternalIdentityNormalized provider profile data
OAuthClientDataClient name, redirect URIs, allowed grants, scopes
OAuthAuthorizationRequestValidated incoming authorization request
OAuthConsentContextUser-approved scopes and remember flag

Convenience Helpers

APIPurpose
TokenContext::companyId()Set company subject and company_id claim
TokenContext::companyIds()Set company_ids claim
TokenContext::tenantId()Set tenant subject and tenant_id claim
TokenContext::tenantIds()Set tenant_ids claim
TokenContext::impersonated()Set impersonation claim
JwtAccessToken::companyId()Read company_id claim
JwtAccessToken::companyIds()Read company_ids claim
JwtAccessToken::tenantId()Read tenant_id claim
JwtAccessToken::tenantIds()Read tenant_ids claim
JwtAccessToken::isImpersonated()Read impersonation state
ApiKeyContext::forCompany()Build company-owned API key context
TokenResponse::extend()Register global token response extension
JwtTokenTestHelperIssue test token pairs

Guards and Middleware

MiddlewareAliasPurpose
AuthenticateJwtsp.jwtAuthenticate bearer JWT via the configured guard
RequireJwtScopesp.jwt.scopeRequire every listed JWT scope
RequireAnyJwtScopesp.jwt.any_scopeRequire any listed JWT scope
AuthenticateApiKeysp.api_keyAuthenticate API key bearer token
RequireApiKeyScopesp.api_key.scopeRequire every listed API key scope
RequireAnyApiKeyScopesp.api_key.any_scopeRequire any listed API key scope
AuthenticateOAuthTokensp.oauthAuthenticate OAuth resource token
RequireOAuthScopesp.oauth.scopeRequire every listed OAuth scope
RequireAnyOAuthScopesp.oauth.any_scopeRequire any listed OAuth scope
RequireOAuthClientsp.oauth.clientRestrict by client id

Artisan Commands

CommandDescription
sp-jwt-auth:installPublish config, migrations, and optionally generate keys
sp-jwt-auth:setupPublish client scaffolding, patch the API guard when safe, and optionally generate keys
sp-jwt-auth:validateValidate client app guard, provider, key, hash key, and JWKS setup
sp-jwt-auth:keysGenerate, rotate, retire, or revoke signing keys
sp-jwt-auth:jwksPrint or export JWKS public key payload
sp-jwt-auth:pruneDelete expired or revoked token rows

Traits

TraitModel Method
HasJwtTokens$user->token(), $user->tokenCan('scope')

Support

ClassDescription
TokenResponsepassportCompatible() helper and global response extensions
HookRegistryRegister pre-issue validation, pre-issue mutation, and post-issue hooks
SpJwtAuthPackage config and key repository accessor facade
SecretHasherHMAC hash/verify for opaque token secrets
HashKeyRepositoryManage active and previous HMAC hash keys
ConfigSigningKeyRepositoryLoad signing keys from package config
JwksFormatterBuild JWKS payload from active and previous signing keys

Events (33 total)

GroupEvents
Core JWTTokenIssued, TokenRefreshed, TokenRevoked, SessionRevoked, AllUserTokensRevoked, RefreshTokenReuseDetected
Account SecurityMfaChallengeCreated, MfaChallengeCompleted, OtpCodeCreated, OtpCodeSent, OtpCodeResent, OtpCodeVerified, OtpCodeFailed, OtpCodeLocked, OtpCodeExpired, EmailVerificationTokenCreated, EmailVerificationSent, EmailVerified, PasswordResetTokenCreated, PasswordResetSent, PasswordResetTokenConsumed
API KeysApiKeyCreated, ApiKeyUsed, ApiKeyRevoked, ApiKeyRotated
External IdentityExternalIdentityResolved
OAuth ServerOAuthClientCreated, OAuthClientSecretRotated, OAuthClientRevoked, OAuthAuthorizationApproved, OAuthAuthorizationDenied, OAuthTokenIssued, OAuthTokenRevoked, OAuthConsentRevoked