Repository navigation
OAuth2Client
Viames Marino edited this page Nov 6, 2026
·
3 revisions
Pair\Models\OAuth2Client manages OAuth2 client credentials and token issuance.
-
createAccessToken(): string— fresh token, database-clock timestamps, no renewal or deletion of other tokens. -
accessTokenResponse(?string $scope = null): JsonResponse— explicit RFC 6749 response. -
issueAccessToken(): string— historical reuse/refresh policy, retained for compatibility. sendAccessTokenResponse(): voidgenerateSecret(int $bytes = 32): string
Lifecycle/config:
-
_init()defines fields and validation rules
use Pair\Models\OAuth2Client;
$client = OAuth2Client::find($clientId);
if (!$client or !$client->enabled) {
throw new RuntimeException('Invalid client');
}
$token = $client->createAccessToken();- Designed for server-to-server OAuth flows.
- The client identifier is the
idprimary key; availability is stored inenabled. - This example assumes the caller has already authenticated the client secret. Finding an enabled client by ID alone does not authenticate it.
-
issueAccessToken()reuses and refreshes a valid token or creates one, then removes other tokens for that client. -
sendAccessTokenResponse()delegates to the new explicit response and terminates. It omits absent scope and emits mandatory no-store/no-cache headers. -
sendLegacyAccessTokenResponse()preserves the old payload and token reuse behavior only for frozen integrations; it is not the standards-compliant emitter. - Validate the client secret and authorize the requested scope before issuing. Scope persistence and authorization remain application responsibilities.
-
accessTokenResponse()validates scope syntax before persisting any token.
See also: OAuth2Token, ApiController.
Maintained by Viames Marino — VM Ingegneria · Professional enquiries
Home · Setup · Configuration
Build with Pair 4
- Generator
- Controllers and responses
- Read models
- ActiveRecord and queries
- Forms and validation
- PairUI.js, PairMotion.js and HTML fragments
APIs and authentication
- API guide and CRUD
- Middleware and rate limits
- Users, sessions, and ACL
- Passkeys and social login
- Native mobile setup
Integrate and operate
- Integrations
- Runtime extensions and adapter keys
- Cache and cache stores
- Logs and observability
- PWA and push
- Packages and distribution
- Upgrade to v4