Apple sign-In, worked successfully and next day stopped working

I am working on the backend of our iOs App for apple sign in. The backend of our app is designed in Ubuntu 14.04 and using framework Codeigniter in PHP.

I been following this link from the start.

Code Block html
https://developer.okta.com/blog/2019/06/04/what-the-heck-is-sign-in-with-apple


but then the JWT token wasn't working for me and apple auth was sending me the following error.

Code Block JSON
{"error":"invalid_client"}


I tried a few library and when I used this library [ameen-sarsour] (https://gist.github.com/ameen-sarsour/e14a1d5bae5b61080dfdd5b1430c3e10) for generating the JWT token i.e. client_secret and this library [GriffinLedingham/php-apple-signin] (https://github.com/GriffinLedingham/php-apple-signin) to decrypt the id_token code. The above error turned into

Code Block JSON
{"error":"invalid_grant"}


After using the fresh auth_code from the iOs. I started receiving the following response from Apple.

I used the TEAM_ID, KEY_ID & CLIENT_ID as I received from Apple. I successfully received the following response from Apple side.


Code Block JSON
{
"access_token":"...",
"token_type":"Bearer",
"expires_in":3600,
"refresh_token":"....",
"id_token": "..."
}


I designed the backend of the App for registration and login with Apple sign-in.
The next day, the same code is started to throw the following error.
Code Block JSON
{"error":"invalid_grant"}


Its been a few days now and I am still stuck on this issue.

I also looked into CURL URL provided here [generateandvalidate_tokens] (https://developer.apple.com/documentation/sign_in_with_apple/generate_and_validate_tokens)

Code Block Terminal Response
curl -v POST "https://appleid.apple.com/auth/token" \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'client_id=com.Myapp.app' \
-d 'client_secret=<client secret jwt code>' \
-d 'code=<auth_code from ios App>' \
-d 'grant_type=authorization_code'


Here is the response of the above code in the attachment




It's showing HTTP 400 in response. Please suggest solution for this issue.