Path in the Gestor bibliotecas/oauth2.php
Issues and validates the tokens external systems use to call the Gestor API (_api/…). It is not the social login (oauth.php).
Tokens
oauth2_gerar_token_client_credentials(['id_usuarios' => …, 'grant_type' => 'client_credentials', 'scope' => …]) takes an already authenticated user and returns:
{ "access_token": "…", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "…", "scope": "read" }-
Both tokens use the Gestor JWT format, signed with the site's private RSA key (
chaves/gestor/privada.key, viaautenticacao_gerar_jwt_chave_privada()). -
Each one has a random
pubID, stored inoauth2_tokenswith theUSUARIO_HASH_PASSWORDHMAC, IP, User-Agent and expiration. Revoking a token means deleting the row. -
Lifetime:
oauth2.token-expiration(3600 s) andoauth2.refresh-token-expiration(30 days), from$_CONFIG. -
A user has at most
oauth2.maximo-tokens-usuario(5) active access tokens: the oldest is revoked (oauth2_fifo_ids_para_revogar()). -
Every issuance first deletes the expired tokens of all users (
oauth2_limpar_tokens_expirados()).
Validating and renewing
-
oauth2_autorizar_requisicao()readsAuthorization: Bearer <token>and callsoauth2_validar_token(), which checks the signature with the public key, thepubIDand HMAC in the database, theaccesstype, the expiration and whether the user is active. It returnsid_usuarios,nome,email,usuario,id_usuarios_perfisandscope, orfalse. -
oauth2_renovar_token(['refresh_token' => …])validates the refresh token, deletes it (single use) and issues a new pair. The previous access token stays valid until it expires.
Functions
Generated from gestor/bibliotecas/oauth2.php · 6 functions
oauth2_fifo_ids_para_revogar
view source · line 23 ↗oauth2_fifo_ids_para_revogar($tokens, $maximo)Calcula os IDs que devem ser revogados antes de inserir um novo access token. Mantém no máximo $maximo tokens pelo critério FIFO (data e ID como desempate).
Parameters
$tokens$maximo
oauth2_gerar_token_client_credentials
view source · line 56 ↗oauth2_gerar_token_client_credentials(array $params = false): array|falseGera tokens OAuth 2.0 usando credenciais de usuário do sistema.
Parameters
$paramsarray- Parâmetros da função
Returns
oauth2_validar_token
view source · line 245 ↗oauth2_validar_token(array $params = false): array|falseValida token OAuth 2.0.
Parameters
$paramsarray- Parâmetros da função
Returns
oauth2_autorizar_requisicao
view source · line 367 ↗oauth2_autorizar_requisicao(array $params = false): array|falseAutoriza requisição usando token OAuth 2.0.
Parameters
$paramsarray- Parâmetros da função
Returns
oauth2_limpar_tokens_expirados
view source · line 401 ↗oauth2_limpar_tokens_expirados(): boolLimpa tokens OAuth 2.0 expirados da tabela oauth2_tokens.
Returns
oauth2_renovar_token
view source · line 427 ↗oauth2_renovar_token(array $params = false): array|falseRenova access token usando refresh token.
Parameters
$paramsarray- Parâmetros da função
Returns