We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.
Forum Discussion
donaldp
3 years agoCollaborator | Level 9
expired token when set to not expire
Have read a few posts on related topics here, and something definitely not working correctly...
My app was doing weird things today, and I saw a expired token exception getting thrown. This has...
Greg-DB
Dropbox Staff
Thanks for following up. I can't say for sure exactly what happened here, but I'm glad to hear you got this working. For reference, any given access token, expired or not, shouldn't cause an API call to hang. The server would respond with either success or an error, or the call would eventually time out if there's a network issue. If you can reproduce the issue though, let us know how to do so and we'll be happy to look into it.
donaldp
3 years agoCollaborator | Level 9
Hi Greg-DB ,
Now that I have my hands on an expired token again (and a bit of time) I'm circling back to this issue, as I'm now seeing the same results (and I want to get all my expired access token catching handled before I turn back to the code changes I still need to make for refresh tokens).
So, as before I'm using GetCurrentAccountAsync to test if the token is valid (since there's no method to check if a token is valid). I have a global exception catcher in the root of the app. I also have the GetCurrentAccountAsync call in a try/catch (and this itself is being called by an AuthoriseAsync method, which is also in a try/catch). Despite all this, the GetCurrentAccountAsync call never returns, never catches an exception, and yet the expired access token exception does indeed show up in my global exception catcher, so I don't know how it's showing up there but not getting caught by any of the local catches (which of course is where you want to deal with it in the first place)?
So here's the relevant lines of code...
// Root of the App
public App() {
AppDomain.CurrentDomain.FirstChanceException+=CurrentDomain_FirstChanceException;
...
private void CurrentDomain_FirstChanceException(object sender,System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e) {
Trace.WriteLine($"********************************** UNHANDLED EXCEPTION! Details: {e.Exception}");
}
// Dropbox class
public async Task AuthoriseAsync(string code="")
{
Trace.Write($"******************* {nameof(AuthoriseAsync)} has started\r\n");
Trace.Write($"******************* DxAccessToken is {DxAccessToken}\r\n");
try {
if (DxAccessToken is string s && s!=string.Empty) {
await GetAccountNameAsync();
...
catch (Exception ex) {
Trace.Write($"******************* EXCEPTION! in {nameof(AuthoriseAsync)} {ex.Message}\r\n");
}
public async Task<string> GetAccountNameAsync(string NameType="")
{
Trace.Write($"******************* {nameof(GetAccountNameAsync)} has started\r\n");
try {
Trace.Write($"******************* {nameof(GetAccountNameAsync)} is getting account info\r\n");
Account account=await DxClient.Users.GetCurrentAccountAsync();
Trace.Write($"******************* DisplayName is {account.Name.DisplayName}\r\n");
...
catch (Exception ex) {
DxS=$"******************* EXCEPTION! {ex.Message}";
UserNameText="Not logged in";
And here's the relevant output...
******************* AuthoriseAsync has started
******************* DxAccessToken is sl.BOypWqVzNCIJWfm3j..........
******************* GetAccountNameAsync has started
******************* GetAccountNameAsync is getting account info
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body); Request Id: f9474eb56bf049b7ac81dad99e59ce34
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(); Request Id: f9474eb56bf049b7ac81dad99e59ce34
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/..
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body); Request Id: 49117d5a4aea489c8dac85b8fefac953
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/..
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(); Request Id: 49117d5a4aea489c8dac85b8fefac953
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/..
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body); Request Id: ad3db026e54c44318576b21a4ad53526
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/..
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(); Request Id: ad3db026e54c44318576b21a4ad53526
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/..
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body); Request Id: 5033af5fb84943c6aef843ff3c8a6664
********************************** UNHANDLED EXCEPTION! Details: Dropbox.Api.AuthException: expired_access_token/..
at Dropbox.Api.DropboxRequestHandler.RequestJsonString(String host, String routeName, String auth, RouteStyle routeStyle, String requestArg, Stream body)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(); Request Id: 5033af5fb84943c6aef843ff3c8a6664
So none of those catches actually work - as far as I can see the app just gets stuck trying to get the account name with an expired token - and the exception only shows up in the global exception catcher in the root of the app. Do you know what's going on here? Oh also AuthoriseAsync is being called from the Dropbox class constructor (so the user doesn't have to login again if the token is still valid) - might be relevant.
Now that I know how to get the actual expiry-time of the token I can write some code around that, but also I would like to make sure all my exception-catching is working, and it's clearly not when it comes to calling GetCurrentAccountAsync.
thanks,
Donald.
- Greg-DB3 years agoDropbox Staff
donaldp Unfortunately it's not clear why that is occurring for you. I just tried and I am able to catch the expired_access_token Exception from a GetCurrentAccountAsync call when made with a DropboxClient with an expired short-lived access token and no refresh token.
I can't offer much insight with .NET or C# itself, but it sounds like there may be something about your project/environment impacting how exception handling is working for you. Do you have any unusual configuration in your project or environment?
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,875 PostsLatest Activity: 2 years agoIf you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!