carropublic / myinfo
PHP 与 MyInfo 集成
4.0.0
2024-02-27 17:36 UTC
Requires
- guzzlehttp/guzzle: ^7.4.3
- illuminate/support: ~5|~6|~7|~8|~9|~10
- web-token/jwt-core: ^3.2
Requires (Dev)
- phpunit/phpunit: ^9.3.8
- squizlabs/php_codesniffer: ^3.3
This package is not auto-updated.
Last update: 2024-09-24 20:50:21 UTC
README
这是一个用于MyInfo的 Laravel 包。您可以在他们的页面上了解更多关于 MyInfo 的信息。有一个[公开] MyInfo 集成演示客户端应用程序,它是基于 Nodejs 的。因此,我基于他们的 Nodejs 演示实现了自己的 Laravel 包。
查看contributing.md以查看待办事项列表。
安装
通过 Composer
$ composer require carropublic/myinfo
用法
运行 php artisan vendor:publish
,这将把 private.pem
和 public.pem
移动到您的 storage/ssl
文件夹。我从 MyInfo 演示页面获取了私钥/公钥对。您必须使用自己的。
设置环境
MYINFO_AUTHORIZE_API="https://test.api.myinfo.gov.sg/com/v3/authorise"
MYINFO_TOKEN_API="https://test.api.myinfo.gov.sg/com/v3/token"
MYINFO_PERSON_API="https://test.api.myinfo.gov.sg/com/v3/person"
MYINFO_CALLBACK_URL="https://:3001/callback"
MYINFO_CLIENT_ID="STG2-MYINFO-SELF-TEST"
MYINFO_CLIENT_SECRET="44d953c796cccebcec9bdc826852857ab412fbe2"
MYINFO_REALM="https://:3001"
MY_INFO_PRIVATE_KEY="ssl/private.pem"
MY_INFO_PUBLIC_KEY="ssl/public.pem"
MYINFO_ATTRIBUTES="uinfin,name,sex,race,nationality,dob,email,mobileno,regadd,housingtype,hdbtype,marital,edulevel,noa-basic,ownerprivate,cpfcontributions,cpfbalances"
MYINFO_PURPOSE="demonstrating MyInfo APIs"
用法:
您可以创建一个自定义 URL,如下所示。
MyInfo::createAuthorizeUrl($code); # $code in this case for state
当用户同意检索他们的信息时,它将重定向到您配置的 MYINFO_CALLBACK_URL
。然后您需要处理以下内容:
// This is the state that you passed when creating authorize URL
$state = $request->input('state');
// This is the authorizon code
$code = $request->input('code');
// Create token request base on authorize code
$myInfoToken = MyInfo::createTokenRequest($code);
$token = json_decode($myInfoToken, true);
if (!$token) {
// handle error when there is no token
}
$jwtPayload = MyInfo::getJWTPayload($token['access_token']);
if(!$jwtPayload) {
// handle error when there is problem with getting JWT
}
$userUniFin = $jwtPayload['sub'];
// Create person request
$personRequest = MyInfo::createPersonRequest(
$userUniFin,
$token['access_token']
);
if(!$personRequest) {
// handle error when there is problem with person request
}
// Get user data using private key
$userData = MyInfo::getUserData(
$personRequest,
storage_path(config('myinfo.keys.private'))
);
变更日志
请参阅changelog以获取最近更改的更多信息。
测试
$ composer test
贡献
请参阅contributing.md以获取详细信息及待办事项列表。
安全
如果您发现任何安全相关的问题,请通过作者邮箱而不是使用问题追踪器来联系。
鸣谢
许可
许可。请参阅许可文件以获取更多信息。