Open attie-argentum opened 2 years ago
We have encountered a similar issue when using incremental authorization with Google APIs. In our app there are two different login screens which request different scopes. If a user uses only one of these screens, everything is good. If they use one login screen and later access the other, the oauth callback from Google for the second login screen will return the combined scopes that the user has granted, not just the scopes requested at the second screen.
According to this commit the API in oauthlib for handling a scope change is to catch a Warning
exception, check if the modified scopes are acceptable and then extract the token from the exception if they are. In the context of the fetch_token
call in requests-oauthlib this is problematic because the exception is thrown in a mutating method before the token is saved to the OAuth2Session.token
field. Although the token can be extracted from the Warning
, it won't be saved to the session.
I'm trying to set up OAuth2 for unattended access to Microsoft IMAP servers - the
refresh_token
is important here.When providing a request scope set as follows:
offline_access
https://outlook.office.com/User.Read
https://outlook.office.com/IMAP.AccessAsUser.All
The service responds with the following (i.e:
offline_access
is removed):https://outlook.office.com/User.Read
https://outlook.office.com/IMAP.AccessAsUser.All
This results in a warning being raised.
Traceback
``` Traceback (most recent call last): File "./oauth2-test.py", line 51, inApparently the
offline_access
scope should never be returned by Microsoft services, as it's not actually a useful scope for accessing resources (ref).My current approach (which isn't ideal), is as follows:
I'm aware of
OAUTHLIB_RELAX_TOKEN_SCOPE
(link), but that seems perhaps a little over-permissive.Perhaps one of the following would be a good idea?