Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refreshing authorization not working with expired or invalid access token #36

Closed
aspik opened this issue Jul 26, 2018 · 5 comments
Closed

Comments

@aspik
Copy link

aspik commented Jul 26, 2018

It is not possible to refresh the authorization, if the client is "restarted".
old implementation:
https://github.com/henrikfroehling/TraktApiSharp/blob/master/Source/Lib/TraktApiSharp/Authentication/TraktAuthentication.cs#L376
new implementation:

In the new version there is only a check, if the authentication is authorized. During a refresh the authentication is always not authorized, therefore it is not possible to do a refresh. Please bring back the old check :)

@henrikfroehling
Copy link
Owner

@aspik Could you please provide the steps on how to reproduce this error? And a stack trace would be nice.

@aspik
Copy link
Author

aspik commented Jul 27, 2018

Sure:

  1. start the client,
  2. authorize with pin:
    https://github.com/aspik/TraktPluginMP2/blob/master/TraktPluginMP2/TraktPluginMP2/Models/TraktSetupModel.cs#L120
  3. save the response to file:
    https://github.com/aspik/TraktPluginMP2/blob/master/TraktPluginMP2/TraktPluginMP2/Models/TraktSetupModel.cs#L269-L274
  4. close the client,
  5. start the client,
  6. refresh the authorization by exchanging the refresh token:
    https://github.com/aspik/TraktPluginMP2/blob/master/TraktPluginMP2/TraktPluginMP2/Services/LibrarySynchronization.cs#L447-L464
    https://github.com/aspik/TraktPluginMP2/blob/master/TraktPluginMP2/TraktPluginMP2/Services/TraktClientProxy.cs#L58

Result: exception with message: "not authorized" is thrown.

I'm afraid that the stack trace will not be helpful. I'm using a wrapper around the TraktClient (for unit tests purpose ), and I can catch only the AggregateException:
https://github.com/aspik/TraktPluginMP2/blob/master/TraktPluginMP2/TraktPluginMP2/Services/TraktClientProxy.cs#L281-L294

@henrikfroehling
Copy link
Owner

henrikfroehling commented Jul 27, 2018

@aspik I think, you didn't set the saved authorization in the client.
https://github.com/aspik/TraktPluginMP2/blob/master/TraktPluginMP2/TraktPluginMP2/Services/LibrarySynchronization.cs#L460

There might be missing this:

_traktClient.Authorization = savedAuth;

See the example "Serialize and deserialize authorization information" at https://github.com/henrikfroehling/Trakt.NET#basic-usage

@aspik
Copy link
Author

aspik commented Jul 27, 2018

This was not needed with the old lib. And tbh I'm not sure why I have to do it? :) its only the refreshtoken which matters.
I just restored back the old check in the new version, compiled it and exchanged in my plugin. Now is all working as before :)

@henrikfroehling
Copy link
Owner

Ah, okay. You're right, that should also work with just the refresh token.

@henrikfroehling henrikfroehling added this to the Version 1.0.0 Beta 1 milestone Jul 27, 2018
@henrikfroehling henrikfroehling changed the title not possible to refresh the authorization Refreshing authorization not working with expired or invalid access token Jul 27, 2018
@henrikfroehling henrikfroehling mentioned this issue Nov 24, 2018
60 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants