zenodo / zenodo-rdm

Zenodo, powered by InvenioRDM
https://zenodo.org/
GNU General Public License v2.0
36 stars 25 forks source link

Oauth fetch token endpoint gives error "invalid_grant' with 401 error code inconsistently #878

Open pkdash opened 3 weeks ago

pkdash commented 3 weeks ago

We have a web application that has integration with Zenodo repository application. Zenodo users can login to our app and be able to interact with Zenodo using the Zenodo api. Recently we are seeing issues with fetching the token from Zenodo. When we are trying to retrieve the token, sometimes we get "invalid_grant" error with http code 401. We have created a ticket in our repo related to this issue. Here is a code snippet I was using to reproduce the issue:

import requests
res = requests.post(
    'https://zenodo.org/oauth/token',    
    data={
        'grant_type': 'authorization_code',        
        'code': '<AUTHORIZATION_CODE>',
        'scope': 'deposit:write deposit:actions',
        'client_id': '<CLIENT_ID>',
        'client_secret': '<CLIENT_SECRET>',        
        'redirect_uri': '<REDIRECT_URL>',
    }
)

The only thing that changes between multiple post requests (when trying to reproduce this error) to fetch the token is the AUTHORIZATION_CODE. This code we get using the endpoint https://zenodo.org/oauth/authorize Again, we get the invalid_grant error occasionally and it is easy to reproduce.

Any help in resolving this issue will be very much appreciated.