alancting / php-adfs-jwt
A simple library to encode and decode Microsoft Active Directory Federation Services (ADFS) JSON Web Tokens (JWT) in PHP, conforming to RFC 7519
1.0.2
2020-10-07 07:07 UTC
Requires
- php: >=5.3.0
Requires (Dev)
- php-coveralls/php-coveralls: ^2.3
- phpunit/phpunit: >=4.8 <=9
This package is auto-updated.
Last update: 2024-11-16 15:56:12 UTC
README
PHP-ADFS-JWT
No longer maintained.
Please moved to https://github.com/alancting/php-microsoft-jwt
A simple library to encode and decode Microsoft Active Directory Federation Services (ADFS) JSON Web Tokens (JWT) in PHP, conforming to RFC 7519.
Forked From firebase/php-jwt
Installation
Use composer to manage your dependencies and download PHP-ADFS-JWT:
composer require alancting/php-adfs-jwt
Example
<?php use Alancting\Adfs\JWT\Adfs\AdfsConfiguration; use Alancting\Adfs\JWT\Adfs\AdfsAccessTokenJWT; use Alancting\Adfs\JWT\Adfs\AdfsIdTokenJWT; $openid_configuration_url = 'https://[Your ADFS hostname]/adfs/.well-known/openid-configuration'; $client_id = 'your_client_id'; /** * AdfsConfiguration will fetch the issuers, audiences and jwks for jwt validation */ $adfs_configs = new AdfsConfiguration($openid_configuration_url, $client_id); $id_token_jwt = 'id.token.jwt'; $access_token_jwt = 'access.token.jwt'; /** * If the jwt is invalid, exception will be thrown. */ $access_token = new AdfsAccessTokenJWT($adfs_configs, $access_token_jwt); echo "\n"; // Getting the payload from access token print_r($access_token->getPayload()); echo "\n"; $id_token = new AdfsIdTokenJWT($adfs_configs, $id_token_jwt); echo "\n"; // Getting the unique_name(username) from id token echo $id_token->getUsername(); echo "\n"; // Getting the payload from id token print_r($id_token->getPayload()); echo "\n"; /** * You might want to 'cache' the tokens for expire validation * To check whether the access token and id token are expired, simply call */ echo ($access_token->isExpired()) ? 'Access token is expired' : 'Access token is valid'; echo ($id_token->isExpired()) ? 'Id token is expired' : 'Id token is valid';
Tests
Run the tests using phpunit:
$ composer run test