PHP code example of m4n50n / oauth2-azure-bundle
1. Go to this page and download the library: Download m4n50n/oauth2-azure-bundle 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/ */
m4n50n / oauth2-azure-bundle example snippets
// config/bundles.php
return [
// ...
M4n50n\OAuth2AzureBundle\OAuth2AzureBundle::class => ['all' => true],
];
use M4n50n\OAuth2AzureBundle\Factory\OAuth2AzureFactory;
final class LoginController extends AbstractController
{
public function __construct(private OAuth2AzureFactory $OAuth2AzureFactory)
{
}
#[Route(path: '/login/azure', name: 'login_azure', methods: ['GET'])]
public function user_azureLoginRequest(JWTTokenManagerInterface $JWTManager, UserPasswordHasherInterface $userPasswordHasher)
{
try {
// ...
$auth = $this->OAuth2AzureFactory->getAuth($this->request);
$ownerData = $auth->getOwnerData();
/* It returns an array with the following structure:
$ownerData = [
"aud" => "c3db02f0-401c-452c......",
"iss" => "https://login.microsoftonline.com/....../v2.0",
"iat" => 1360114,
"profileImage" => "", // base64_encode of the image binary
"email":"[email protected] ",
"name":"Jose Garcia",
// ... (other fields)
];
*/
// ...
} catch (\Exception $exception) {
// ...
}
// ...
}
}