I'm trying to do a web application using the OAuthlib to login with google, this is what the google object looks like:
google = oauth.remote_app('google',
request_token_url=None,
access_token_method='POST',
request_token_params={'scope': 'email'},
access_token_url='https://accounts.google.com/o/oauth2/token',
authorize_url='https://accounts.google.com/o/oauth2/auth',
consumer_key="my consumer",
consumer_secret="my secret",
base_url='https://www.googleapis.com/oauth2/v1/'
)
The problem I hve is when I get the user information from google, his is my authorization view:
@app.route('/login/authorized/<provider>')
def authorized():
resp = google.authorized_response()
auth_error(resp)
id_token = json.load(resp['id_token'])
login_user(me, True)
return redirect(url_for('index'))
So, what I try to do with the json.load is to decode the information google gives me, in this particular case, the response has an id_token which is a long string that, according to my research, is a json encoded string that when it is decoded, provides all the user information, no matter how much I try I can't seem to find the correct way to decode it, the error I get is:
AttributeError: 'unicode' object has no attribute 'read'
On the json.load line.
EDIT: after decoding the id_token I would then use it to get or create the user in my own database.
I am using Flask and the library is json.
If anyone could explain the correct way to decode the string into a python object I would appreciate it a lot, or if this is not json but some other type of coded string please do tell. Thank you very much in advance.