From 01558bbddf6c0ae349ddfa4f66278f4f70f6e90d Mon Sep 17 00:00:00 2001 From: Gao Sun Date: Mon, 1 Jul 2024 12:49:18 +0800 Subject: [PATCH] refactor(console): fix php guide (#6143) --- .../src/assets/docs/fragments/_checkpoint.md | 2 +- .../src/assets/docs/guides/web-php/README.mdx | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/packages/console/src/assets/docs/fragments/_checkpoint.md b/packages/console/src/assets/docs/fragments/_checkpoint.md index 2abf8cde580..49d2692bc90 100644 --- a/packages/console/src/assets/docs/fragments/_checkpoint.md +++ b/packages/console/src/assets/docs/fragments/_checkpoint.md @@ -2,5 +2,5 @@ Now, you can test your application: 1. Run your application, you will see the sign-in button. 2. Click the sign-in button, the SDK will init the sign-in process and redirect you to the Logto sign-in page. -3. After you signed in, you will be redirected back to your application and see user data and the sign-out button. +3. After you signed in, you will be redirected back to your application and see the sign-out button. 4. Click the sign-out button to sign out. diff --git a/packages/console/src/assets/docs/guides/web-php/README.mdx b/packages/console/src/assets/docs/guides/web-php/README.mdx index 227184c46d3..6a2c6ef0cd9 100644 --- a/packages/console/src/assets/docs/guides/web-php/README.mdx +++ b/packages/console/src/assets/docs/guides/web-php/README.mdx @@ -28,8 +28,8 @@ composer require logto/sdk Insert the following code into your PHP file: -{`use logto\sdk\LogtoClient; -use Logto\Sdk\LogtoConfig; +{`use Logto\\Sdk\\LogtoClient; +use Logto\\Sdk\\LogtoConfig; $client = new LogtoClient( new LogtoConfig( @@ -53,7 +53,7 @@ By default, the SDK uses the built-in PHP session to store the Logto data. If yo - + @@ -123,7 +123,7 @@ In Logto SDK, we can use `$client->isAuthenticated()` to check the authenticatio We also need to implement a home page for demonstration: - If the user is not signed in, show a sign-in button; -- If the user is signed in, show some basic information about the user. +- If the user is signed in, show a sign-out button. ```php title="index.php" Route::get('/', function () { @@ -131,25 +131,10 @@ Route::get('/', function () { return "Not authenticated Sign in"; } - return ( - // Get local ID token claims - json_decode($client->getIdTokenClaims()) - . "
" - // Fetch user info from Logto userinfo endpoint - json_decode($client->fetchUserInfo()) - . "
Sign out" - ); + return "Sign out"; }); ``` -Our data models are based on [JsonModel](https://github.com/logto-io/php/blob/master/docs/api/classes/Logto/Sdk/Models/JsonModel.md), which is safe to accept undefined keys while encoding or decoding JSON. - -Note that a field (claim) with `null` value doesn't mean the field is set. The reason may be the related scope is not requested, or the user doesn't have the field. - -For example, if we didn't request the `email` scope when signing in, and the `email` field will be `null`. However, if we requested the `email` scope, the `email` field will be the user's email address if available. - -To learn more about scopes and claims, see [Get user information](https://docs.logto.io/quick-starts/php/#get-user-information). -
@@ -179,6 +164,14 @@ Route::get('/userinfo', function () { }); ``` +Our data models are based on [JsonModel](https://github.com/logto-io/php/blob/master/docs/api/classes/Logto/Sdk/Models/JsonModel.md), which is safe to accept undefined keys while encoding or decoding JSON. + +Note that a field (claim) with `null` value doesn't mean the field is set. The reason may be the related scope is not requested, or the user doesn't have the field. + +For example, if we didn't request the `email` scope when signing in, and the `email` field will be `null`. However, if we requested the `email` scope, the `email` field will be the user's email address if available. + +To learn more about scopes and claims, see [Get user information](https://docs.logto.io/quick-starts/php/#get-user-information). +