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.
Implements the OAuth 2.0 / 2.1 client side — covers Authorization Code (with PKCE), Client Credentials, Device Code and refresh-token flows. Includes a tiny embedded HTTP listener for the redirect URI.
TsgcHTTP_OAuth2_Client
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Configure ClientId / ClientSecret / Scope / Endpoints (or use a Provider preset for Google / Microsoft / GitHub), call StartAuthorization, then use Token in your HTTP calls.
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();
Implements the OAuth 2.0 client surface with PKCE, refresh-token rotation and an embedded loopback redirect listener.
Authorization Code (with optional PKCE per RFC 7636), Client Credentials (RFC 6749 §4.4), Device Code (RFC 8628) and Refresh Token (RFC 6749 §6) are all supported as typed methods.
Toggle OAuth2Options.PKCE — the component generates the code_verifier / code_challenge pair and includes them per RFC 7636 (mandatory in OAuth 2.1).
Sibling components TsgcHTTP_OAuth2_Client_Google and TsgcHTTP_OAuth2_Client_Microsoft ship with the right endpoints and scopes pre-filled. Use the base class for everyone else.
The component spins up a tiny embedded HTTP listener on the configured RedirectURL, captures the authorization code, then shuts the listener down — no external web server required.
SaveToFile / LoadFromFile persist the refresh token (encrypted-at-rest if configured) so the user is not prompted on every app launch.
Pair with TsgcHTTPComponentClient, TsgcHTTP2Client or TsgcWebSocketClient via Authentication.Token.OAuth2 — the bearer token is injected on every request automatically.
Authoritative sources for the standards this component implements.
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.
| Online Help — TsgcHTTP_OAuth2_Client Full property, method and event reference for this component. | Open | |
| Demo Project — Demos\20.HTTP_Protocol\02.OAuth2_Authentication Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |