1. Go to this page and download the library: Download accredifysg/singpass-login library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
accredifysg / singpass-login example snippets
public function handle(SingPassSuccessfulLoginEvent $event): void
{
$singPassUser = $event->getSingPassUser();
$nric = $singPassUser->nric;
if (! $nric) {
// NRIC is only available when the 'user.identity' scope is requested.
throw new SingPassLoginException;
}
$user = User::where('nric', '=', $nric)->first();
if (! $user) {
throw new SingPassLoginException;
}
Auth::login($user);
}
use Accredifysg\SingPassLogin\Events\CorpPassSuccessfulLoginEvent;
class CorpPassLoginListener
{
public function handle(CorpPassSuccessfulLoginEvent $event): void
{
$corpPassUser = $event->getCorpPassUser();
// Entity (company/organisation)
$entityId = $corpPassUser->getEntityId(); // UEN
$entityName = $corpPassUser->getEntityName();
// Actor (individual user)
$nric = $corpPassUser->getIdentityNumber(); // NRIC/FIN (
use Accredifysg\SingPassLogin\Events\CorpPassDataRetrievedEvent;
class CorpPassDataListener
{
public function handle(CorpPassDataRetrievedEvent $event): void
{
$data = $event->getCorpPassData();
// Authorization data from the UserInfo endpoint
$authInfo = $data['auth_info'] ?? [];
$tpAuthInfo = $data['tp_auth_info'] ?? [];
}
}
use Accredifysg\SingPassLogin\Exceptions\AuthFlowException;
use Accredifysg\SingPassLogin\Exceptions\AuthenticationErrorException;
use Accredifysg\SingPassLogin\Exceptions\JwtPayloadException;
use Accredifysg\SingPassLogin\Exceptions\JweDecryptionFailedException;
use Accredifysg\SingPassLogin\Exceptions\JwksInvalidException;
use Accredifysg\SingPassLogin\Exceptions\JwksException;
use Accredifysg\SingPassLogin\Exceptions\JwtDecodeFailedException;
use Accredifysg\SingPassLogin\Exceptions\OpenIdDiscoveryException;
use Accredifysg\SingPassLogin\Exceptions\PushedAuthorizationRequestException;
use Accredifysg\SingPassLogin\Exceptions\SingPassLoginException;
use Accredifysg\SingPassLogin\Exceptions\TokenExchangeException;
use Accredifysg\SingPassLogin\Exceptions\MissingConfigException;
use Accredifysg\SingPassLogin\Exceptions\UserInfoRequestException;
use Accredifysg\SingPassLogin\Exceptions\UserInfoDecryptionException;
use Accredifysg\SingPassLogin\Exceptions\UserInfoVerificationException;