0

I'm trying to access token using authorization code flow. I'm using authorization_code as the grant type. Following documentation at Django OAuth

Here's my code that's making the post request:

curl --location --request POST 'http://127.0.0.1:8000/o/token/' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cache-Control: no-cache' \
--header 'Accept: application/json' \
--data-urlencode 'client_id=ngta3GGa3jP6Rmv5Tspj97Bk4aiitHgv1EQilCDS' \
--data-urlencode 'client_secret=zLwMyuXg7WCSFwUDYBxFP3QxHh5mF6xM2hBsKyvRbypac5lV7fl2NoFeeDG3afWWxLedA7qtzD2Mvf68qyBra3A4iUXXlDXJO4LvxuZv4UULU6NLWlObpD0ylQSXbwZD' \
--data-urlencode 'code=q4NfBMbyTNbcIQZ4j7SfgMWL898psv' \
--data-urlencode 'redirect_uri=http://localhost:8000/no/callback/' \
--data-urlencode 'code_verifier=b'\''SlJDWEgyRzNYMks0RTVQVDlRVkFaOFdDUkxHV1A3QURMTjNITFdaMTBLU0tWQkkzMUVWVEZFU0k='\''' \
--data-urlencode 'grant_type=authorization_code'

I'm expecting to get an access token when I make the post request, but I'm getting this error: { "error": "invalid_grant" }

The grant is valid i.e not expired. Server time is in sync with machine time. Expiry time is 5 minutes but doesnt work even before it's expired.

  • Invalid grant could be a number of things are you sure your code hasnt been used before, what about the time on your machine is it in sync with NTP? – Linda Lawton - DaImTo Jan 31 '23 at 08:14
  • Hello, thanks for your comment. I've added some more details to the question. Can you guide me regarding NTP? How do I check that? And what do you mean by "code hasn't been used before"? – Yusra Masood Feb 01 '23 at 07:22

0 Answers0