PHP code example of jeremy379 / laravel-openid-connect
1. Go to this page and download the library: Download jeremy379/laravel-openid-connect library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jeremy379 / laravel-openid-connect example snippets
# app/Entities/IdentityEntity.php
namespace App\Entities;
use League\OAuth2\Server\Entities\Traits\EntityTrait;
use OpenIDConnect\Claims\Traits\WithClaims;
use OpenIDConnect\Interfaces\IdentityEntityInterface;
class IdentityEntity implements IdentityEntityInterface
{
use EntityTrait;
use WithClaims;
/**
* The user to collect the additional information for
*/
protected User $user;
/**
* The identity repository creates this entity and provides the user id
* @param mixed $identifier
*/
public function setIdentifier($identifier): void
{
$this->identifier = $identifier;
$this->user = User::findOrFail($identifier);
}
/**
* When building the id_token, this entity's claims are collected
*/
public function getClaims(): array
{
return [
'email' => $this->user->email,
];
}
}
$config = Configuration::forSymmetricSigner(
new \Lcobucci\JWT\Signer\Rsa\Sha256(),
InMemory::file(base_path('oauth-public.key')) //This is the public key generate by passport. You need to share it.
);
//Parse the token
$token = $config->parser()->parse($idtoken);
$signatureValid = $config->validator()->validate($token, new \Lcobucci\JWT\Validation\Constraint\SignedWith($config->signer(), $config->signingKey()));