I'm using OAuth to access private data on AGOL. Below is the Python code I'm running on my server:
payload <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">'client_id'</SPAN><SPAN class="punctuation token">:</SPAN> config<SPAN class="punctuation token">.</SPAN>UTILISYNC_ESRI_APP_CLIENT_ID<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'refresh_token'</SPAN><SPAN class="punctuation token">:</SPAN> refresh_token<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'grant_type'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'refresh_token'</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'expiration'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">20160</SPAN><SPAN class="punctuation token">}</SPAN>
response <SPAN class="operator token">=</SPAN> requests<SPAN class="punctuation token">.</SPAN>post<SPAN class="punctuation token">(</SPAN>request_url<SPAN class="punctuation token">,</SPAN> params<SPAN class="operator token">=</SPAN>payload<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>It executes successfully and I get a token that I can use to access the private AGOL data. However, the expiration I indicated is 2 weeks (20160), but the token expire after 30 or 40 minutes. What happens is I load the private services into my webpage using the Javascript API and the token I received from above. But after 30 or 40 minutes when I pan or zoom and the layer should be refreshed, instead I get an invalid token error on my console and the layer doesn't load.
That is why I would like to know, is there a way I can get the expiration of the token? If I could submit the token to some endpoint and discover that token will actually expire sooner, then I will preemptively refresh the token before that happens.
Also, if anyone has any ideas why my token isn't lasting 2 weeks like I think it should, that would be great to know too!
Thanks!