fusionauth / fusionauth-client
PHP编写的FusionAuth客户端
Requires
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^10.5.8
- dev-main
- 1.53.0
- 1.52.1
- 1.52.0
- 1.51.2
- 1.51.1
- 1.51.0
- 1.49.1
- 1.49.0
- 1.48.2
- 1.48.1
- 1.48.0
- 1.47.1
- 1.47.0
- 1.46.0
- 1.45.4
- 1.45.3
- 1.45.2
- 1.45.1
- 1.45.0
- 1.44.0
- 1.43.2
- 1.43.1
- 1.43.0
- 1.42.1
- 1.42.0
- 1.41.3
- 1.41.2
- 1.41.1
- 1.41.0
- 1.40.2
- 1.40.1
- 1.40.0
- 1.39.0
- 1.38.1
- 1.38.0
- 1.37.2
- 1.37.1
- 1.37.0
- 1.36.8
- 1.36.7
- 1.36.6
- 1.36.5
- 1.36.4
- 1.36.3
- 1.36.2
- 1.36.1
- 1.36.0
- 1.35.0
- 1.34.1
- 1.34.0
- 1.33.0
- 1.32.1
- 1.32.0
- 1.31.0
- 1.30.2
- 1.30.1
- 1.30.0
- 1.29.4
- 1.29.3
- 1.29.2
- 1.29.1
- 1.29.0
- 1.28.1
- 1.28.0
- 1.27.2
- 1.27.1
- 1.27.0
- 1.26.1
- 1.26.0
- 1.25.0
- 1.24.0
- 1.23.3
- 1.23.2
- 1.23.1
- 1.23.0
- 1.22.2
- 1.22.1
- 1.22.0
- 1.21.0
- 1.20.1
- 1.20.0
- 1.19.8
- 1.19.7
- 1.19.6
- 1.19.5
- 1.19.4
- 1.19.3
- 1.19.2
- 1.19.1
- 1.19.0
- 1.18.8
- 1.18.7
- 1.18.6
- 1.18.5
- 1.18.4
- 1.18.3
- 1.18.2
- 1.18.1
- 1.18.0
- 1.17.5
- 1.17.4
- 1.17.3
- 1.17.2
- 1.17.1
- 1.17.0
- 1.16.1
- 1.16.0
- 1.16.0-RC.1
- 1.15.8
- 1.15.7
- 1.15.6
- 1.15.5
- 1.15.4
- 1.15.3
- 1.15.2
- 1.15.1
- 1.15.0
- 1.14.0
- 1.13.3
- 1.13.2
- 1.13.1
- 1.13.0
- 1.12.1
- 1.12.0
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.1-RC.1
- 1.8.0-RC.1
- 1.7.4
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.1
- 1.3.0
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- dev-1.52.0.maintenance
- dev-1.51.1.maintenance
- dev-jj/release-workflow
- dev-feature/custom-themes
- dev-feature/custom-scopes
- dev-feature/touchup
- dev-1.48.2.maintenance
- dev-1.45.2.maintenance
- dev-1.43.0.maintenance
- dev-staging
- dev-1.45.0.maintenance
- dev-spencer/1738
- dev-spencer/1911/gis-one-tap
- dev-spencer/1939/gis-migration
- dev-1.42.0.maintenance
- dev-jto/max-ttl-1729
- dev-spencer/1912
- dev-spencer/1947
- dev-spencer/2010
- dev-spencer/test-refactor
- dev-spencer/778
- dev-jto/fixes1883
- dev-spencer/webauthn
- dev-defect-1918
- dev-johnathon/redirect_uri-wildcard
- dev-spencer/webauth-apple
- dev-spencer/issue-1699
- dev-spencer/issue-633
- dev-spencer/issue-971
- dev-spencer/issue-1547
- dev-spencer/issue-1676
- dev-rob/issue-1589
This package is auto-updated.
Last update: 2024-09-05 22:55:14 UTC
README
简介
如果您要将FusionAuth集成到PHP应用程序中,这个库将加快您的开发速度。请确保查看我们的SDK使用建议页面。
有关FusionAuth的更多信息和相关文档,请参阅https://fusionauth.io。
安装
使用客户端库的最佳方式是使用Composer安装以下包:fusionauth/fusionauth-client
。请在项目根目录中运行以下命令。
composer require fusionauth/fusionauth-client
然后,在您的PHP文件中包含composer
自动加载器。
require __DIR__ . '/vendor/autoload.php';
示例
设置
首先,您必须确保有一个运行的FusionAuth实例。如果您还没有,最简单的方法是通过Docker安装,但还有其他方法。默认情况下,它将在localhost:9011
上运行。
然后,您必须在管理UI中创建一个API密钥,以便调用API端点。
现在,您可以开始使用这个库了!
错误处理
在每次请求之后,您需要检查是否有任何错误并进行处理。为了避免混乱,我们在下一个示例中省略了错误处理,但您应该做一些类似以下的事情。
// $result is the response of one of the endpoint invocations from the examples below if (!$result->wasSuccessful()) { echo "Error!" . PHP_EOL; echo "Got HTTP {$result->status}" . PHP_EOL; if (isset($result->errorResponse->fieldErrors)) { echo "There are some errors with the payload:" . PHP_EOL; var_dump($result->errorResponse->fieldErrors); } if (isset($result->errorResponse->generalErrors)) { echo "There are some general errors:" . PHP_EOL; var_dump($result->errorResponse->generalErrors); } }
创建客户端
要向API发送请求,首先您需要使用创建的API密钥和FusionAuth运行的服务器地址创建一个FusionAuthClient
实例。
$client = new FusionAuth\FusionAuthClient( apiKey: "<paste the API Key you generated here>", baseURL: "https://:9011", // or change this to whatever address FusionAuth is running on );
创建应用程序
要创建一个应用程序,请使用createApplication()
方法。
$result = $client->createApplication( applicationId: null, // Leave this empty to automatically generate the UUID request: [ 'application' => [ 'name' => 'ChangeBank', ], ], ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response var_dump($result->successResponse->application);
向现有应用程序添加角色
要向应用程序添加角色,请使用createApplicationRole()
。
$result = $client->createApplicationRole( applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc', // Existing Application Id roleId: null, // Leave this empty to automatically generate the UUID request: [ 'role' => [ 'name' => 'customer', 'description' => 'Default role for regular customers', 'isDefault' => true, ], ], ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response var_dump($result->successResponse->role);
检索应用程序详细信息
要获取有关应用程序的详细信息,请使用retrieveApplication()
。
$result = $client->retrieveApplication( applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc', ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response var_dump($result->successResponse->application);
删除应用程序
要删除应用程序,请使用deleteApplication()
。
$result = $client->deleteApplication( applicationId: 'd564255e-f767-466b-860d-6dcb63afe4cc', ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response // Note that $result->successResponse will be empty
锁定用户
要阻止用户登录,请使用deactivateUser()
。
$result = $client->deactivateUser( 'fa0bc822-793e-45ee-a7f4-04bfb6a28199', ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response
注册用户
要在应用程序中注册用户,请使用register()
。
下面的代码还向用户注册添加了一个customer
角色和自定义的appBackgroundColor
属性。
$result = $client->register( userId: 'fa0bc822-793e-45ee-a7f4-04bfb6a28199', request: [ 'registration' => [ 'applicationId' => 'd564255e-f767-466b-860d-6dcb63afe4cc', 'roles' => [ 'customer', ], 'data' => [ 'appBackgroundColor' => '#096324', ], ], ], ); // Handle errors as shown in the beginning of the Examples section // Otherwise parse the successful response
问题和支持
如果您在这个库中找到任何错误,请在此处提交问题。注意,对FusionAuthClient
类的修改必须在FusionAuth 客户端构建器存储库上完成,该存储库负责生成该文件。
但如果您有任何问题或支持问题,我们很乐意听取您的意见。
如果您购买了包含支持的付费计划,请在您的账户门户中提交工单。了解更多关于付费计划的信息。
否则,请在社区论坛中发布您的问题。
贡献
在GitHub上欢迎提交错误报告和拉取请求,请访问https://github.com/FusionAuth/fusionauth-php-client。
注意:如果您想修改FusionAuthClient
类,您必须在FusionAuth 客户端构建器存储库上进行修改,该存储库负责生成我们支持的所有客户端库。
许可
此代码在Apache v2.0 许可证的条款下作为开源软件提供。
升级策略
此库会自动跟踪 FusionAuth API,并可能接收包含错误修复、安全补丁、测试、代码示例或文档更改的更新。
这些发布版本还可能更新依赖项、语言引擎和操作系统,因为我们将遵循它所使用的基础技术的弃用和停用策略。
这意味着,当一个依赖项(例如语言、框架或操作系统)被其维护者弃用时,此库也将被我们弃用,并最终更新为使用较新版本。