PHPackages                             ziming/laravel-myinfo-sg - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. ziming/laravel-myinfo-sg

ActiveLibrary

ziming/laravel-myinfo-sg
========================

Laravel Package for Singapore MyInfo

3.14159265(1mo ago)1630.9k↓29.3%10PHPPHP ^8.4

Since May 29Pushed 2mo ago4 watchersCompare

[ Source](https://github.com/ziming/laravel-myinfo-sg)[ Packagist](https://packagist.org/packages/ziming/laravel-myinfo-sg)[ Docs](https://github.com/ziming/laravel-myinfo-sg)[ GitHub Sponsors](https://github.com/ziming)[ RSS](/packages/ziming-laravel-myinfo-sg/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (24)Versions (71)Used By (0)

Laravel MyInfo Singapore
========================

[](#laravel-myinfo-singapore)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d084825e2891bbe9b1d310314e1a7872c5982a8def44f14e89e1caf0f6b35a40/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a696d696e672f6c61726176656c2d6d79696e666f2d73672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ziming/laravel-myinfo-sg)[![Total Downloads](https://camo.githubusercontent.com/f6e543063d9cd41b814808e5531f1bd562c777adf9c286f8d1225f7590fd0b56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a696d696e672f6c61726176656c2d6d79696e666f2d73672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ziming/laravel-myinfo-sg)

A working PHP Laravel Package for MyInfo Singapore. With the annoying, time wasting hidden quirks of implementing it in PHP figured out.

[Official MyInfo Docs](https://api.singpass.gov.sg/library/myinfo/v3/developers/overview)

Contributing
------------

[](#contributing)

A donation is always welcomed (currently $0), especially if you or your employer makes money with the help of my packages. Which I am aware of a couple.

Is Myinfo v5 supported?
-----------------------

[](#is-myinfo-v5-supported)

### Generate Authorization URI to Redirect to Singpass Myinfo Login Page

[](#generate-authorization-uri-to-redirect-to-singpass-myinfo-login-page)

```
$myinfoConnector = new MyinfoConnector;

$authoriseApiUrl = $myinfoConnector->generateAuthorizationUrl();

// If you want to change the redirect uri you can do this
$authoriseApiUrl = $myinfoConnector->generateAuthorizationUrl('https://www.the-redirect-uri-you-want-to-use.com/callback');
```

### After Singpass Redirect Back to Your Callback URI, Get MyInfo Person Data

[](#after-singpass-redirect-back-to-your-callback-uri-get-myinfo-person-data)

```
$myinfoConnector = new MyinfoConnector;

// If for some reason you need to change your redirect uri again. I cannot remember the use case as I took a very long break from this.
if (App::isLocal() === false) {
    $myinfoConnector
        ->oauthConfig()
        ->setRedirectUri(
            action(SomeControllerAction::class)
        );
}

$myinfoAuthenticator = $myinfoConnector->getAccessToken(
    $code,
    $state,
    session()->pull(config('laravel-myinfo-sg-v5.state_session_key')),
);

$personData = $myinfoConnector
    ->getUser($myinfoAuthenticator)
    ->json();
```

### The JWKS Endpoint

[](#the-jwks-endpoint)

Either you make your own controller or you just generate it and paste it in Singpass API Portal.

Maybe in future I provide better support for it but for now I am drowned in work in a very small team. Sorry.

What about Myinfo v6 with FAPI 2.0?
-----------------------------------

[](#what-about-myinfo-v6-with-fapi-20)

Not yet sorry, but it is in my plans.

Installation (v3 instructions)
------------------------------

[](#installation-v3-instructions)

You can install the package via composer:

```
composer require ziming/laravel-myinfo-sg
```

Followed by adding the following variables to your `.env` file.

The values provided below are the ones provided in the official MyInfo nodejs tutorial.

Change them to the values you are given for your app.

```
MYINFO_APP_CLIENT_ID=STG2-MYINFO-SELF-TEST
MYINFO_APP_CLIENT_SECRET=44d953c796cccebcec9bdc826852857ab412fbe2
MYINFO_APP_REDIRECT_URL=http://localhost:3001/callback
MYINFO_APP_PURPOSE="demonstrating MyInfo APIs"
MYINFO_APP_ATTRIBUTES=uinfin,name,sex,race,nationality,dob,email,mobileno,regadd,housingtype,hdbtype,marital,noa-basic,ownerprivate,cpfcontributions,cpfbalances

MYINFO_APP_SIGNATURE_CERT_PRIVATE_KEY=file:///Users/your-username/your-laravel-app/storage/myinfo-ssl/stg-demoapp-client-privatekey-2018.pem
MYINFO_SIGNATURE_CERT_PUBLIC_CERT=file:///Users/your-username/your-laravel-app/storage/myinfo-ssl/staging_myinfo_public_cert.cer

MYINFO_DEBUG_MODE=false

# SANDBOX ENVIRONMENT (no PKI digital signature)
MYINFO_AUTH_LEVEL=L0
MYINFO_API_AUTHORISE=https://sandbox.api.myinfo.gov.sg/com/v3/authorise
MYINFO_API_TOKEN=https://sandbox.api.myinfo.gov.sg/com/v3/token
MYINFO_API_PERSON=https://sandbox.api.myinfo.gov.sg/com/v3/person

# TEST ENVIRONMENT (with PKI digital signature)
#MYINFO_AUTH_LEVEL=L2
#MYINFO_API_AUTHORISE=https://test.api.myinfo.gov.sg/com/v3/authorise
#MYINFO_API_TOKEN=https://test.api.myinfo.gov.sg/com/v3/token
#MYINFO_API_PERSON=https://test.api.myinfo.gov.sg/com/v3/person

# Controller URI Paths. IMPORTANT
MYINFO_CALL_AUTHORISE_API_URL=/redirect-to-singpass
MYINFO_GET_PERSON_DATA_URL=/myinfo-person

```

Lastly, publish the config file

```
php artisan vendor:publish --provider="Ziming\LaravelMyinfoSg\LaravelMyinfoSgServiceProvider" --tag="myinfo-sg-config"
```

You may also wish to publish the MyInfo official nodejs demo app ssl files as well to storage/myinfo-ssl. You should replace these in your production environment.

```
php artisan vendor:publish --provider="Ziming\LaravelMyinfoSg\LaravelMyinfoSgServiceProvider" --tag="myinfo-ssl"
```

Usage and Customisations
------------------------

[](#usage-and-customisations)

When building your button to redirect to SingPass. It should link to `route('myinfo.singpass')`

After SingPass redirects back to your Callback URI, you should make a post request to `route('myinfo.person')`

If you prefer to not use the default routes provided you may set `enable_default_myinfo_routes` to `false` in `config/laravel-myinfo-sg.php` and map your own routes. This package controllers will still be accessible as shown in the example below:

```
