Skip to content

OAuth2Client

Viames Marino edited this page Oct 19, 2026 · 2 revisions

Pair framework: OAuth2Client

Pair\Models\OAuth2Client manages OAuth2 client credentials and token issuance.

Main methods

  • issueAccessToken(): string
  • sendAccessTokenResponse(): void
  • generateSecret(int $bytes = 32): string

Lifecycle/config:

  • _init() defines fields and validation rules

Implementation example

use Pair\Models\OAuth2Client;

$client = OAuth2Client::find($clientId);

if (!$client or !$client->enabled) {
	throw new RuntimeException('Invalid client');
}

$token = $client->issueAccessToken();

Notes

  • Designed for server-to-server OAuth flows.
  • The client identifier is the id primary key; availability is stored in enabled.
  • 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() writes standardized token payload output and terminates execution.

See also: OAuth2Token, ApiController.

Clone this wiki locally