I hit the same problem, the problem is about the algorithm to generate the secret_token. (For more information: https://stackoverflow.com/a/64114694/13799822)
teamid is AppID
clientid is bundle ID
keyid is KeyID
keyfile is the path to .p8 file
This is the sample code for generating the secret_token.
NOTED: *Seem the authorizationCode expirations is 5 minutes, so please make sure the authorizationCode is valid before making the request.*
require 'jwt'
Update these values with your app's information
team_id = '' #AppID
client_id = '' #bundle ID
key_id = '' #KeyID
key_file = './AuthKey_XXXX.p8'
Define the JWT's headers and claims
headers = {
	The token must be signed with your key
	'kid' => key_id,
	'alg' => 'ES256'
}
claims = {
	The token is issued by your Apple team
	'iss' => team_id,
	The token applies to Apple ID authentication
	'aud' => 'https://appleid.apple.com',
	The token is scoped to your application
	'sub' => client_id,
	The token is valid immediately
	'iat' => Time.now.to_i,
	The token expires in 6 months (maximum allowed)
	'exp' => Time.now.to_i + 86400*180,
}
Read in the key and generate the JWT
ecdsa_key = OpenSSL::PKey::EC.new IO.read key_file
token = JWT.encode claims, ecdsa_key, 'ES256', headers
Print the JWT to stdout
puts token