Open iamsarthakjoshi opened 4 years ago
The scope appears to be reverting to the default scope between the first and second view. Is there a possibility the cache is being changed by another part of your code in-between?
The results are consistent with scope
not being passed into OAuth2Credentials.__init__()
the second time around.
I have the same problem. Whereas it also gives me the access_tokens and refresh_tokens
@iamsarthakjoshi I resolved it with creating new credentials object in callback instead of passing old state
I am having the same issue, however the OAuth2Credentials scope is being defined correctly. When I go to verify it says the scope has changed to the same list of scopes provided by OP. After inspecting the value of the scope after construction, it is set to the same as it was in the start_auth_view.
The scope in both instances (start_auth_view and callback) is: ['offline_access', 'accounting.contacts.read', 'accounting.transactions.read', 'accounting.attachments.read']
However it gives the following error: Scope has changed from "accounting.transactions.read offline_access accounting.attachments.read accounting.contacts.read" to "accounting.attachments.read openid accounting.transactions.read offline_access accounting.journals.read accounting.reports.read accounting.contacts.read accounting.transactions projects accounting.attachments profile accounting.settings accounting.settings.read email accounting.contacts assets".
If you need any more contextual information please let me know.
Any help in resolving this other than drastically increasing the requested scope would be appreciated.
I have figured out the issue.
The application you are connecting to has previously granted the user a much larger scope than you are now requesting.
Xero does not reset the scope history of an account / application relationship when disconnecting that application from the organisation. As a result, the only way to reduce the scope granted by an application to a particular account is to delete the application from the Xero Developer portal and link to a new one. The Xero Support team told me that scopes are accumulative and if you have ever requested a larger scope previously it will always return that scope in the access token being granted.
Considering this, the only way to receive the exact scope you are expecting is to:
Once you have done this, the scope you receive will be as expected.
If you don't mind that the scope has changed during the request, you can add the following to your settings.py file: os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] = 'True'
This will tell the OAuth requests lib to not care about a changing scope during the request.
Thanks for sharing the solution!
Thanks for sharing the solution!
Glad the solution could help, I've been on and off trying to figure this out for a while, hopefully it will save others time in the future
Is there something we can do in PyXero to make this "handled" better?
(Or is this resolved and I can close it?)
Is there something we can do in PyXero to make this "handled" better?
(Or is this resolved and I can close it?)
I think it's resolved as there is nothing you can really do on your end, other than maybe providing more information on this particular problem in your docs?
I don't understand this problem. I haven't tried changing the scopes in the process, but while verifying with request_uri (after the two-factor authentication) the problem appears every time saying "Scope has changed from...to ..."
Any help is kindly appreciated. :)
Thank you.