mirror of
https://github.com/logto-io/logto.git
synced 2025-02-17 22:04:19 -05:00
refactor(console): fix php guide (#6143)
This commit is contained in:
parent
4727062544
commit
01558bbddf
2 changed files with 14 additions and 21 deletions
|
@ -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.
|
||||
|
|
|
@ -28,8 +28,8 @@ composer require logto/sdk
|
|||
Insert the following code into your PHP file:
|
||||
|
||||
<Code title="index.php" className="language-php">
|
||||
{`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
|
|||
|
||||
</Step>
|
||||
|
||||
<Step title="Implement the sign-in route">
|
||||
<Step title="Configure redirect URIs">
|
||||
|
||||
<RedirectUrisWeb />
|
||||
|
||||
|
@ -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 <a href='/sign-in'>Sign in</a>";
|
||||
}
|
||||
|
||||
return (
|
||||
// Get local ID token claims
|
||||
json_decode($client->getIdTokenClaims())
|
||||
. "<br>"
|
||||
// Fetch user info from Logto userinfo endpoint
|
||||
json_decode($client->fetchUserInfo())
|
||||
. "<br><a href='/sign-out'>Sign out</a>"
|
||||
);
|
||||
return "<a href='/sign-out'>Sign out</a>";
|
||||
});
|
||||
```
|
||||
|
||||
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).
|
||||
|
||||
</Step>
|
||||
|
||||
<Step title="Checkpoint: Test your application">
|
||||
|
@ -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).
|
||||
|
||||
</Step>
|
||||
|
||||
</Steps>
|
||||
|
|
Loading…
Add table
Reference in a new issue