oauth2
OAuth 2.0 client for authenticating with Google, GitHub, Discord and any OAuth2 provider. Handles auth code flow, token exchange and refresh.
Install
ppm install oauth2
Usage Example
uses oauth2;
var cfg: TOAuth2Config;
cfg.ClientID := 'my-app-id';
cfg.ClientSecret := 'secret';
cfg.AuthURL := 'https://accounts.google.com/o/oauth2/auth';
cfg.TokenURL := 'https://oauth2.googleapis.com/token';
cfg.RedirectURI := 'http://localhost:8080/callback';
cfg.Scopes := 'email profile';
// Step 1: redirect user to auth URL
var url := GetAuthURL(cfg, 'state-123');
// Step 2: exchange code for token
var token := ExchangeCode(cfg, receivedCode);
WriteLn(token.AccessToken);
// Refresh when expired
var newToken := RefreshToken(cfg, token);
Features
Authorization Code flow with PKCE
Token exchange and automatic refresh
Google, GitHub, Discord support
Secure state parameter handling
Custom provider URL configuration