Expand my Community achievements bar.

Join us for the next Community Q&A Coffee Break on Tuesday April 23, 2024 with Eric Matisoff, Principal Evangelist, Analytics & Data Science, who will join us to discuss all the big news and announcements from Summit 2024!
SOLVED

OAuth2 "invalid_grant" "The authorization code has expired"

Avatar

Level 1

I'm trying to go through the OAuth2 flow as described here https://marketing.adobe.com/developer/documentation/authentication-1/auth-web-server-1

When I get to the final step of exchanging the authorization code for an access token I'm receiving a response with a http status code of 400 with an error of invalid_grant and an error_description of "The authorization code has expired" even though I using the authorization code within at most a couple of minutes of getting it. I'm posting to https://api.omniture.com/token with "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" and a body of "client_id=f77aa38da2-spredfasttestapplication&client_secret=XXXX&redirect_uri=https%3A%2F%2Fdevbox.spredfast.com%2Fcredential%2Fomniture&grant_type=authorization_code&code=eb0141c5b1110c75d4f72598572595307b9fa2a1"

Logging output is 

2015/08/18 09:12:00:418 CDT [DEBUG] wire - http-outgoing-0 >> "POST /token HTTP/1.1[\r][\n]" 2015/08/18 09:12:00:418 CDT [DEBUG] wire - http-outgoing-0 >> "Accept: application/json[\r][\n]" 2015/08/18 09:12:00:418 CDT [DEBUG] wire - http-outgoing-0 >> "Content-Length: 228[\r][\n]" 2015/08/18 09:12:00:419 CDT [DEBUG] wire - http-outgoing-0 >> "Content-Type: application/x-www-form-urlencoded; charset=UTF-8[\r][\n]" 2015/08/18 09:12:00:419 CDT [DEBUG] wire - http-outgoing-0 >> "Host: api.omniture.com[\r][\n]" 2015/08/18 09:12:00:419 CDT [DEBUG] wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]" 2015/08/18 09:12:00:419 CDT [DEBUG] wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.3.1 (java 1.5)[\r][\n]" 2015/08/18 09:12:00:419 CDT [DEBUG] wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]" 2015/08/18 09:12:00:419 CDT [DEBUG] wire - http-outgoing-0 >> "[\r][\n]" 2015/08/18 09:12:00:419 CDT [DEBUG] wire - http-outgoing-0 >> "client_id=f77aa38da2-spredfasttestapplication&client_secret=XXXX&redirect_uri=https%3A%2F%2Fdevbox.spredfast.com%2Fcredential%2Fomniture&grant_type=authorization_code&code=eb0141c5b1110c75d4f72598572595307b9fa2a1" 2015/08/18 09:12:00:750 CDT [DEBUG] wire - http-outgoing-0 << "HTTP/1.1 400 Bad Request[\r][\n]" 2015/08/18 09:12:00:750 CDT [DEBUG] wire - http-outgoing-0 << "Date: Tue, 18 Aug 2015 14:11:59 GMT[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "Server: Apache/2.4.2[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "Cache-Control: no-cache[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "Vary: Accept-Encoding,User-Agent[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "Content-Encoding: gzip[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "xserver: scapivm17[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "X-Cnection: close[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "Transfer-Encoding: chunked[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "Content-Type: application/json[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "[\r][\n]" 2015/08/18 09:12:00:751 CDT [DEBUG] wire - http-outgoing-0 << "59[\r][\n]" 2015/08/18 09:12:00:752 CDT [DEBUG] wire - http-outgoing-0 << "[0x1f][0x8b][0x8][0x0][0x0][0x0][0x0][0x0][0x0][0x3]$[0xca][0xc1][0x9][0x80]0[0xc][0x5][0xd0]UB[0xce]N[0xe0][0x1c][0xde]%4[0xc1][0x6][0xa4])[0xbf]UDqw[0x15][0xaf][0x8f]w[0xb1][0x1][0x1][0x1e][0xd9][0xcb].[0xab][0xeb][0xbc]@J[0xe7][0xe1][0xf7]Y[0xad]%x[0xed][0x1e][0xe5]=S6[0x92][0xad][0xe7][0x80][0x9f][0xf2][0x19][0xa5]P[0xa3],[0x8d][0xec][0xa8][0xe]S[0xbe][0x1f][0x0][0x0][0x0][0xff][0xff][\r][\n]"

Any suggestions for what's causing this.

1 Accepted Solution

Avatar

Correct answer by
Level 1

Turns out it had expired. You have to be very quick using the authorization code. Even waiting a minute seems to be too long.

View solution in original post

1 Reply

Avatar

Correct answer by
Level 1

Turns out it had expired. You have to be very quick using the authorization code. Even waiting a minute seems to be too long.