Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://login.microsoftonline.com/common/oauth2/v2.0/token` resulted in a `400 Bad Request`

Md Jamil Uddin 41 Reputation points
2021-10-13T09:32:08.273+00:00

Hi,

My code was working fine. I started to get this error after refreshing:

Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://login.microsoftonline.com/common/oauth2/v2.0/token resulted in a 400 Bad Request response: {"error":"invalid_grant","error_description":"AADSTS54005: OAuth2 Authorization code was already redeemed, please retry (truncated...) in C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php:113 Stack trace: #0 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\guzzle\src\Middleware.php(69): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL) #1 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response)) #2 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL) #3 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise{closure}() #4 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\Promise.php(248): GuzzleHttp\Promise\TaskQueue->run(true) #5 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\Promise.php(224): GuzzleHttp\Promise\Promise->invokeWaitFn() #6 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\Promise.php(269): GuzzleHttp\Promise\Promise->waitIfPending() #7 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\Promise.php(226): GuzzleHttp\Promise\Promise->invokeWaitList() #8 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\promises\src\Promise.php(62): GuzzleHttp\Promise\Promise->waitIfPending() #9 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\guzzle\src\Client.php(187): GuzzleHttp\Promise\Promise->wait() #10 C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\guzzle\src\ClientTrait.php(95): GuzzleHttp\Client->request('POST', 'https://login.m...', Array) #11 C:\xampp\htdocs\SbcertAudit\vendor\adnanhussainturki\microsoft-api-php\src\Auth.php(98): GuzzleHttp\Client->post('https://login.m...', Array) #12 C:\xampp\htdocs\SbcertAudit\callback.php(52): myPHPnotes\Microsoft\Auth->getToken('0.AXQAPJzrZ27Gy...', '161903') #13 {main} thrown in C:\xampp\htdocs\SbcertAudit\vendor\guzzlehttp\guzzle\src\Exception\RequestException.php on line 113

Using: Microsoft API PHP Wrapper

Any ideas?

Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,371 Reputation points
    2021-10-14T02:46:39.17+00:00

    This is a very common error. The authorization code cannot be redeemed for the access token multiple times, and it will become invalid after it is used once. You only need to run your authorization URL again and log in to the user to get a new authorization code.


    If an Answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.