Authentication and authorization on APIGEE using Python

1k views Asked by At

I am trying to find a way to authenticate and authorize a client to access APIGEE. I can't seem to get it to function. I am using Python Requests-OAuthlib. Here is my code:

 from requests_oauthlib import OAuth2Session

 client_id = r'my_client_id'
 client_secret = r'my_client_secret'
 redirect_uri = 'https://api.usergrid.com/org/app'

 oauth = OAuth2Session(client_id, redirect_uri=redirect_uri)
 authorization_url, state = oauth.authorization_url('https://api.usergrid.com/org/app/token', grant_type='client_credentials')
 redirect_response = raw_input(authorization_url)
 token = oauth.fetch_token('https://api.usergrid.com/org/app/token', client_secret=client_secret, authorization_response=redirect_response)

 url = "https://api.usergrid.com/org/app/my_collection"
 r = oauth.get(url)

I get an error: "Please supply either code or authorization_code parameters."

Any ideas on what I am doing wrong? I am using the APIGEE docs found here: http://apigee.com/docs/app-services/content/authenticating-users-and-application-clients

Thank you in advance.

1

There are 1 answers

0
Santanu Dey On

Your client is sending response_type=code in the authorization request. That is why the server is not performing client credential Oauth.

This could be a default behavior of your python client. In that case you might want to use a simple http client to keep things under control.