NSManagedHuman / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
0 stars 0 forks source link

OAuth2Credentials implements to_json and from_json methods but fails direct json enconding #243

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
[Use this form for both apiclient and oauth2client issues]

What steps will reproduce the problem?
1. Create an instance of oauth2client.client.OAuth2Credentials (possibly from 
oauth_flow.step2_exchange()
2. Try serializing it via json, for example: json.b64encode(credentials_value)
3. It will fail because "object is not serializable" despite having a to_json() 
method

What is the expected output? What do you see instead?

We would expect a JSON serialized object as response.

What version of the product are you using? On what operating system?

Version 1.0, appengine flavor.

Please provide any additional information below.

I came up with this particular issue when adapting the Python example for the 
new G+ sign-in from Flask to webapp2 
(https://developers.google.com/+/quickstart/python). webapp2 uses a 
SecureCookieSerializer which access json.b64encode() internally -- see: 
https://code.google.com/p/webapp-improved/source/browse/webapp2_extras/securecoo
kie.py

A possible solution would be to subclass and implement a default() method for 
json.JSONEncoder().

Original issue reported on code.google.com by azugal...@gmail.com on 3 Mar 2013 at 2:53

GoogleCodeExporter commented 8 years ago
To serialize a Credentials object to JSON call to_json().

Never store a Credentials object in a cookie, it contains the applications 
client id and client secret.

Original comment by jcgregorio@google.com on 4 Mar 2013 at 2:25

GoogleCodeExporter commented 8 years ago
That works. Thank you for pointing that out.

Original comment by azugal...@gmail.com on 7 Mar 2013 at 3:20