ekapusta/oauth2-esia
Laravel/PHP OAuth2 client for Russia’s ESIA (Gosuslugi) authentication. Provides ESIA OAuth flow integration, token handling, and user profile retrieval to add ESIA login to your application with minimal setup.
ekapusta/oauth2-esia package is tailored for Estonia’s national e-identity authentication system (ESIA), enabling OAuth2-based authentication and retrieval of user personal data (e.g., name, ID code, etc.). This is a niche but critical fit for:
encryption facade) should be baked in.Socialite as a bridge or build a custom Auth Guard for ESIA.esia_user trait) into controllers.config/oauth.php or a dedicated esia.php config file.User model or create a EsiaUser pivot table to store ESIA-specific claims (e.g., personal_code, given_name).users table or a oauth_tokens table.| Risk Area | Severity | Mitigation |
|---|---|---|
| ESIA API Changes | High | Implement feature flags and versioned endpoints in your API. Monitor ESIA’s status page or changelog. |
| Token Revocation | Medium | Use refresh tokens and build a token revocation webhook listener. |
| CSRF/State Attacks | High | Enforce strict state binding and validate state params on redirect. |
| Data Mapping Errors | Medium | Validate ESIA response schema against your User model (e.g., use Laravel’s ValidatesWhenResolved). |
| Rate Limiting | Medium | Implement exponential backoff for ESIA API calls (e.g., Guzzle middleware). |
| Multi-Tenancy | Low | If supporting multiple ESIA clients, use tenant-aware config (e.g., esia_clients table). |
league/oauth2-client (base for oauth2-esia).guzzlehttp/guzzle (for HTTP clients).laravel/socialite (optional, for unified auth).// Example PKCE flow with Axios
const codeVerifier = generateCodeVerifier();
const codeChallenge = await generateCodeChallenge(codeVerifier);
window.location.href = `/esia/auth?code_challenge=${codeChallenge}`;
esia.php)./esia/callback route to handle redirects.EsiaService::syncUser()).EsiaTokenManager).openssl, curl, json (required for OAuth2).personal_code, given_name). Extend your User model accordingly:
class User extends Authenticatable {
protected $casts = [
'personal_code' => 'string',
'esia_token' => 'object',
];
}
https://yourapp.com/esia/callback).php artisan vendor:publish --provider="Ekapusta\Oauth2Esia\EsiaServiceProvider"
.env:
ESIA_CLIENT_ID=your_id
ESIA_CLIENT_SECRET=your_secret
ESIA_REDIRECT_URI=https://yourapp.com/esia/callback
Auth::loginUsingId() after callback.User model:
$esiaUser = $esiaService->getAuthenticatedUser($token);
$user = User::updateOrCreate(
How can I help you explore Laravel packages today?