accredifysg/singpass-login
Laravel package for SingPass Login, MyInfo, and CorpPass using FAPI 2.0-style auth: OpenID discovery, Pushed Authorization Requests (PAR) with DPoP, PKCE, and private-key JWT client assertions. Includes shared services and thin provider controllers.
## Getting Started
This package, **SingPass-Login**, enables seamless integration with Singapore's SingPass and Corppass authentication systems via FAPI 2.0. To get started:
1. **Installation**: Require the package via Composer:
```bash
composer require accredifysg/singpass-login
php artisan vendor:publish --provider="Accredify\SingPassLogin\SingPassServiceProvider"
Update .env with your FAPI credentials (client ID, secret, and callback URL).use Accredify\SingPassLogin\Facades\SingPass;
$authUrl = SingPass::getAuthorizationUrl();
return redirect()->away($authUrl);
Handle the callback via the provided SingPassCallbackController or manually verify tokens.Initiate Login:
$authUrl = SingPass::getAuthorizationUrl([
'scope' => 'openid profile email',
'state' => 'unique_random_string', // CSRF protection
]);
scope to request user data (e.g., openid, profile, email).state in the session for validation.Callback Handling:
code.code for a token:
$token = SingPass::getAccessToken($authorizationCode);
$userInfo = SingPass::getUserInfo($token);
state parameter to prevent CSRF attacks.Token Management:
SingPass::refreshToken($refreshToken).Auth::loginUsingId($userInfo['sub']); // Assuming 'sub' is the user ID
Strict Types:
declare(strict_types=1)). Ensure your project and dependencies are compatible.FAPI 2.0 Mandatory:
/auth/realms/singpass/protocol/openid-connect/auth)..env to reflect the new FAPI 2.0 base URL:
SINGPASS_FAPI_BASE_URL=https://fapi2.singpass.gov.sg
Token Handling:
web-token/jwt-framework dependency was updated to v4.1.3. If you rely on custom JWT logic, test thoroughly for compatibility.Token Validation Errors:
SingPass::validateToken($token) to debug token issues.'debug' => env('SINGPASS_DEBUG', false),
Corppass-Specific Issues:
CSRF Protection:
state parameter in the callback to prevent CSRF attacks. Example:
if (!hash_equals(session('singpass_state'), $request->state)) {
abort(403, 'Invalid CSRF state');
}
Custom User Mapping:
singpass.login event:
event(new \Accredify\SingPassLogin\Events\LoginEvent($userInfo));
Token Storage:
SingPassTokenManager to implement custom storage (e.g., Redis):
SingPass::setTokenManager(new CustomTokenManager());
Middleware:
Route::middleware(['auth.singpass'])->group(function () {
// Protected routes
});
---
**Note**: This assessment assumes the package is for **Laravel** (as per your request). Adjustments may be needed if the package has broader PHP support. The focus is on **FAPI 2.0/Corppass** changes and strict typing in v3.0.0.
How can I help you explore Laravel packages today?