Je développe une application Web en PHP avec une authentification via l'API OAUTH de Microsoft. Je rencontre un souci avec le mécanisme d'authentification. En effet, l'appel (Methode GET) et le retour (Methode POST) a l'API se font bien mais je n'arrive pas à récupérer la variable $_POST['access_token']
alors que dans le header de la page les informations sont présente (voir capture).
Pouvez-vous me venir en aide svp ?
Captures :
Image 1 : https://ibb.co/LkzhrXG
Image 2 : https://ibb.co/p4J7tqf
Documentation :
https://learn.microsoft.com/fr-fr/azure/active-directory/develop/v2-oauth2-auth-code-flow
Mon code :
index.php :
<?php
include 'config.php';
?>
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>Se connecter</h1>
<a href="https://login.microsoftonline.com/<?= TENANT_ID ?>/oauth2/v2.0/authorize?client_id=<?= APP_ID ?>&redirect_uri=<?= urlencode(SITE_URL) ?>&response_type=token&scope=<?= SCOPE ?>&response_mode=form_post">Cliquer ICI</a>
<?= $_POST['access_token']; ?>
</body>
</html>
config.php :
<?php
define('APP_ID', '***APP ID***');
define('TENANT_ID', '***TENANT ID***');
define('SECRET', '***SECRET***');
define('SCOPE', 'Directory.ReadWrite.All');
define('SITE_URL', 'http://localhost/test');
?>
J'ai finalement trouvé la solution sur un forum : https://stackoverflow.com/questions/45558937/php-microsoft-azure-oauth2-token-post-method-not-working
L'API ne répond pas aux requêtes HTTP, il faut passer par de l'HTTPS ce qui n'était pas le cas dans mon environnement de test.