I got the REST API for a specific service as part of the beta. I was told that authorization went through OAuth2.
I got the following:
I also got a sample code in Ruby:
client = OAuth2::Client.new(key, secret, :site => site) token = client.password.get_token(' your_email@mail.com ', 'your_password') access_token = OAuth2::AccessToken.new(client, token) JSON.parse access_token.get("/v1/users/me").body rescue {}
I am trying to implement the same fragment in python with the oauth2 package without success:
consumer = oauth2.Consumer(key=self._client_id, secret=self._client_secret) request_token_url = "api.theservice.com/" token = oauth2.Token(key=self._email, secret=self._password) client = oauth2.Client(consumer, token) resp, content = client.request(request_token_url, "GET") pprint.pprint(resp) pprint.pprint(content) resp, content = client.request(request_token_url + 'v1/users/me', "GET") pprint.pprint(resp) pprint.pprint(content)
The second answer contains the following:
'www-authenticate': 'Bearer realm="Doorkeeper", error="invalid_token", ' 'error_description="The access token is invalid"',
I also tried creating an oauth2.Client object without a token and checked the first answer for access_token , but none of this happened.
What is the correct authentication method here?
python authentication ruby oauth2
Amir rachum
source share