How can i solve invalid_grant error in getting access token?

Viewed 28

Im trying to get access_token using generated code, but i keep getting invalid_grant error even though i'm using the code that was just created, so i know it has not been expired.

curl_setopt_array($curl, [
   CURLOPT_URL => "https://YOUR_DOMAIN/oauth/token",
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_ENCODING => "",
   CURLOPT_MAXREDIRS => 10,
   CURLOPT_TIMEOUT => 30,
   CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
   CURLOPT_CUSTOMREQUEST => "POST",
   CURLOPT_POSTFIELDS => "grant_type=authorization_code&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&code=CODE&redirect_uri=https://YOUR_DOMAIN/callback",
        CURLOPT_HTTPHEADER => [
        "content-type: application/x-www-form-urlencoded"
      ],
   ]);

The result im getting:

{"error":"invalid_grant","error_description":"Invalid authorization code"}

anything im missing here?

any help is appreciate.

0 Answers
Related