python-unsplash icon indicating copy to clipboard operation
python-unsplash copied to clipboard

Authentication issues

Open IgnaceMaes opened this issue 5 years ago • 7 comments

I've been using the API for two months without any issues, up until a few days ago. There seems to be an issue with the Oauth token fetch.

To make sure the issue isn't on my side I created a new dummy application as follows:

from unsplash.api import Api
from unsplash.auth import Auth

client_id = "x"
client_secret = "x"
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
code = "x"

auth = Auth(client_id, client_secret, redirect_uri, code=code)
api = Api(auth)

api.user.me()

Running this code with a fresh authorization code gives the following error:

Traceback (most recent call last):
  File "C:\...\Python\Python36-32\lib\site-packages\unsplash\auth.py", line 56, in __init__
    self.access_token = self.get_access_token(code)
  File "C:\...\Python\Python36-32\lib\site-packages\unsplash\auth.py", line 72, in get_access_token
    code=code
  File "C:\...\Python\Python36-32\lib\site-packages\requests_oauthlib\oauth2_session.py", line 244, in fetch_token
    self._client.parse_request_body_response(r.text, scope=self.scope)
  File "C:\...\Python\Python36-32\lib\site-packages\oauthlib\oauth2\rfc6749\clients\base.py", line 411, in parse_request_body_response
    self.token = parse_token_response(body, scope=scope)
  File "C:\...\Python\Python36-32\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 379, in parse_token_response
    validate_token_parameters(params)
  File "C:\...\Python\Python36-32\lib\site-packages\oauthlib\oauth2\rfc6749\parameters.py", line 386, in validate_token_parameters
    raise_from_error(params.get('error'), params)
  File "C:\...\Python\Python36-32\lib\site-packages\oauthlib\oauth2\rfc6749\errors.py", line 415, in raise_from_error
    raise cls(**kwargs)
oauthlib.oauth2.rfc6749.errors.InvalidGrantError: (invalid_grant) The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".\testauth.py", line 9, in <module>
    auth = Auth(client_id, client_secret, redirect_uri, code=code)
  File "C:\...\Python\Python36-32\lib\site-packages\unsplash\auth.py", line 59, in __init__
    raise UnsplashAuthError(e)
unsplash.errors.UnsplashAuthError: Unsplash Authentication Error: (invalid_grant) The provided authorization grant is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client.

I'm using Python 3.6 and the version of the dependencies specified in the requirements.txt.

Thanks for any help.

IgnaceMaes avatar Jul 23 '18 21:07 IgnaceMaes

I'm having the same issue.

thejoltjoker avatar Oct 12 '18 08:10 thejoltjoker

Same issue, any news?

lednhatkhanh avatar Apr 17 '19 15:04 lednhatkhanh

+1

ming4J avatar Jul 13 '19 17:07 ming4J

+1 Any updates @yakupadakli ??

adiathavas avatar Jul 19 '19 18:07 adiathavas

+1 Any updates @yakupadakli ??

For anybody still wondering, I wasn't able to find a solution but ended up using another wrapper that works seamlessly https://github.com/salvoventura/pyunsplash

adiathavas avatar Jul 19 '19 18:07 adiathavas

Hello, you need to provide correct client_id, client_secret, redirect_uri and code that returns from redirect uri. You can get token in unsplash developer panel.

Screenshot 2023-11-02 at 16 13 52

yakupadakli avatar Nov 02 '23 13:11 yakupadakli

@yakupadakli How do I used already saved access token so that I don’t have to authorise again again ?

Can you give example ?

khurshid-alam avatar Nov 29 '23 18:11 khurshid-alam