dmlerner / ynab-api

Generated Python API for YNAB
32 stars 10 forks source link

Invalid access token #8

Closed zackelia closed 2 years ago

zackelia commented 2 years ago

The following does not work:

configuration = ynab_api.Configuration(host="https://api.youneedabudget.com/v1")
configuration.api_key["bearer"] = <removed>

with ynab_api.ApiClient(configuration) as client:
    api = user_api.UserApi(client)
    try:
        user = api.get_user()
        print(user)
    except ynab_api.ApiException as err:
        print(err)
$ python main.py        
(401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Server': 'Cowboy', 'Date': 'Sun, 31 Oct 2021 15:36:38 GMT', 'Connection': 'keep-alive', 'Cache-Control': 'no-store', 'Pragma': 'no-cache', 'Www-Authenticate': 'Bearer realm="Doorkeeper", error="invalid_token", error_description="The access token is invalid"', 'Content-Type': 'application/json; charset=utf-8', 'Vary': 'Accept-Encoding, Origin', 'X-Request-Id': <removed>'', 'X-Runtime': '0.007735', 'Strict-Transport-Security': 'max-age=63072000; includeSubDomains', 'Transfer-Encoding': 'chunked', 'Via': '1.1 vegur'})
HTTP response body: {"error":{"id":"401","name":"unauthorized","detail":"Unauthorized"}}

I know my token is valid though:

$ curl -I -H "Authorization: Bearer <removed>" https://api.youneedabudget.com/v1/user
HTTP/1.1 200 OK
...

Currently using the newest release, although it is incorrectly marked as 1.0.0 in setup.py.

dmlerner commented 2 years ago

I think you need the prefix:

configuration.api_key_prefix['bearer'] = 'Bearer'

Let me know if that doesn't fix it for you!

And thanks for mentioning the version, I've just pushed to fix that.

zackelia commented 2 years ago

That worked, thank you! Excited to use this package.