Error occurs when getting the access token from the auth code only for the first access of the day

SOLVED
Go to solution
Highlighted
New Contributor

Error occurs when getting the access token from the auth code only for the first access of the day

I am accessing a web application from Box with Box integration using oauth2.

I am getting the access token from the authorization code I received from Box, but the following error only occurs for the first access of the day.

 

{ "error": "invalid_grant", "error_description": "The authorization code has expired" }

The time from receiving the authorization code to the error is about 10 to 20 seconds.

When I access the web app from Box integration again, the error does not occur.

 

I don't understand why the error occurs only for the first access of the day.

What is the solution?

 

 

3 REPLIES 3
Highlighted
Box Employee

Re: Error occurs when getting the access token from the auth code only for the first access of the d

Hi @西山泰正 

 

Can you verify that you are passing a request with the content-type set to application/x-www-form-urlencoded? 

If you aren't already, that change should address the issues you are seeing. If you continue to see this issue, I may have follow up questions  

Highlighted
New Contributor

Re: Error occurs when getting the access token from the auth code only for the first access of the d

Thank you, @anoland .

The request content type is set to application/x-www-form-urlencoded.

 

Another thing I'm curious about is that the first time I access it every day, it takes a lot of time for my web application screen to appear.

 

1. Select Box integration menu
2. Access my web application (receive authorization code)
3. Access token acquisition error (The authorization code has expired)

 

2-3 is about 10 to 20 seconds.
1 to 3 is about 70 to 80 seconds or more.

 

No error occurs when you access it a second time. At this time, it takes about 10 seconds.

Highlighted
New Contributor

Re: Error occurs when getting the access token from the auth code only for the first access of the d

Thank you, everyone.

 

I understand why only the first access results in an error.

 

When the web application was accessed for the first time from Box integration, it took a very long time to start the web application from IIS and display the screen.
Therefore, it took more than 60 seconds from Box issuing the authorization code to requesting the access token from the web application.

Authentication code is valid for 60 seconds

 

The development environment shuts down the virtual machine every day and starts it in the morning, but it seems that the initial access took time at that time.
I don't think this problem occurs in a production environment as the machine will always boot.

 

Thank you.