OAuth 2.0 Client
OAuth 2.0 / OAuth 2.1 client component — Authorization Code with PKCE, Client Credentials, Device Code, refresh-token rotation and built-in browser flow.
OAuth 2.0 / OAuth 2.1 client component — Authorization Code with PKCE, Client Credentials, Device Code, refresh-token rotation and built-in browser flow.
Implementa o lado cliente do OAuth 2.0 / 2.1 — cobre Authorization Code (com PKCE), Client Credentials, Device Code e fluxos de refresh-token. Inclui um pequeno listener HTTP embutido para o redirect URI.
TsgcHTTP_OAuth2_Client
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Configure ClientId / ClientSecret / Scope / Endpoints (ou use um preset de provedor para Google / Microsoft / GitHub), chame StartAuthorization e use Token nas suas chamadas HTTP.
uses
sgcHTTP;
var
OAuth2: TsgcHTTP_OAuth2_Client;
begin
OAuth2 := TsgcHTTP_OAuth2_Client.Create(nil);
OAuth2.OAuth2Options.ClientId := 'your-client-id';
OAuth2.OAuth2Options.ClientSecret := 'your-client-secret';
OAuth2.OAuth2Options.Scope := 'profile email';
OAuth2.OAuth2Options.RedirectURL := 'http://localhost:5555/callback';
OAuth2.OAuth2Options.AuthorizationURL := 'https://auth.example.com/authorize';
OAuth2.OAuth2Options.TokenURL := 'https://auth.example.com/token';
OAuth2.OAuth2Options.PKCE := True;
// Spawns the user browser at the auth URL
OAuth2.StartAuthorization;
// ... user logs in, browser is redirected to the callback URL
// ... the component captures the code, exchanges for tokens
ShowMessage(OAuth2.AccessToken);
end;
// uses: sgcHTTP
TsgcHTTP_OAuth2_Client *OAuth2 = new TsgcHTTP_OAuth2_Client(this);
OAuth2->OAuth2Options->ClientId = "your-client-id";
OAuth2->OAuth2Options->ClientSecret = "your-client-secret";
OAuth2->OAuth2Options->Scope = "profile email";
OAuth2->OAuth2Options->RedirectURL = "http://localhost:5555/callback";
OAuth2->OAuth2Options->PKCE = true;
OAuth2->StartAuthorization();
Implementa a interface cliente OAuth 2.0 com PKCE, rotação de refresh-token e um listener de redirect loopback embutido.
Authorization Code (com PKCE opcional conforme RFC 7636), Client Credentials (RFC 6749 §4.4), Device Code (RFC 8628) e Refresh Token (RFC 6749 §6) são suportados como métodos tipados.
Ative OAuth2Options.PKCE — o componente gera o par code_verifier / code_challenge e os inclui conforme RFC 7636 (obrigatório no OAuth 2.1).
Os componentes TsgcHTTP_OAuth2_Client_Google e TsgcHTTP_OAuth2_Client_Microsoft já vêm com endpoints e escopos corretos pré-configurados. Use a classe base para outros provedores.
O componente inicia um pequeno listener HTTP embutido na RedirectURL configurada, captura o código de autorização e encerra o listener — sem necessidade de servidor web externo.
SaveToFile / LoadFromFile persistem o refresh token (com criptografia em repouso, se configurado) para que o usuário não precise se autenticar a cada início do aplicativo.
Combine com TsgcHTTPComponentClient, TsgcHTTP2Client ou TsgcWebSocketClient via Authentication.Token.OAuth2 — o bearer token é injetado automaticamente em cada requisição.
Fontes autoritárias para os padrões implementados por este componente.
Acesse a referência do componente, obtenha o projeto de demonstração pronto para executar e baixe a versão de avaliação.
| Ajuda Online — TsgcHTTP_OAuth2_Client Referência completa de propriedades, métodos e eventos deste componente. | Open | |
| Projeto de Demo — Demos\20.HTTP_Protocol\02.OAuth2_Authentication Projeto de exemplo pronto para executar. Incluído no pacote sgcWebSockets — baixe a versão de avaliação abaixo. | Open | |
| Documento Técnico (PDF) Recursos, início rápido, exemplos de código para Delphi & C++ Builder e referências de fonte primária — somente este componente. | Open | |
| Manual do Usuário (PDF) Manual abrangente cobrindo todos os componentes da biblioteca. | Open |