optimizely/optimizely-client-python

Add OAuth functionality -- allow Client to accept OAuth bearer tokens

bexcitement opened this issue · 2 comments

If you send a bearer token from Oauth to:

>>> import optimizely
>>> client = optimizely.Client('abcdefghijklmnopqrstuvwxyz:123456')

You get the following error:

optimizely.error.UnauthorizedError: You did not provide an API token in your request. You need to provide your API token in the Token header. See http://developers.optimizely.com/rest/#authentication for more information, or email us at developers@optimizely.com if you need further assistance. Happy hacking!

This is due to the structure of the requests being slightly different when sending a request with a generated API token versus an OAuth bearer token, (ie. Authorization: Bearer versus Token in header) see below:

Ouath:

curl \
  -H "Authorization: Bearer abcdefghijklmnopqrstuvwxyz" \
  -X GET "https://www.optimizelyapis.com/experiment/v1/projects/1234/"

Generated Token:

curl \
  -H "Token: abcdefghijklmnopqrstuvwxyz:123456" \
  "https://www.optimizelyapis.com/experiment/v1/projects/"

thanks!

This is fixed with @bexcitement 's commit.