0

I've got some problem using the rauth library with flask, python3 and google oauth, python2 works without problems.

It says TypeError: the JSON object must be str, not 'bytes'

Here is the log error:

enter image description here

I've found that Issue here and tried to convert the byte to string

decoder=lambda b: json.loads(str(b))

but without success.

Here is my Implementation

class GoogleSignIn(OAuthSignIn):
def __init__(self):
    super(GoogleSignIn, self).__init__('google')
    self.service = OAuth2Service(
        name='google',
        client_id=self.consumer_id,
        client_secret=self.consumer_secret,
        authorize_url='https://accounts.google.com/o/oauth2/auth',
        access_token_url='https://accounts.google.com/o/oauth2/token',
        base_url='https://www.googleapis.com/plus/v1/people/'
    )

def authorize(self):
    return redirect(self.service.get_authorize_url(
        scope='email',
        response_type='code',
        redirect_uri=self.get_callback_url())
    )

def callback(self):
    if 'code' not in request.args:
        return None, None, None
    oauth_session = self.service.get_auth_session(
        data={'code': request.args['code'],
              'grant_type': 'authorization_code',
              'redirect_uri': self.get_callback_url()},
        decoder=json.loads
    )
    me = oauth_session.get('me').json()
    me_email = None
    for e in me['emails']:
        if e['type'] == 'account':
            me_email = e['value']
    return (
        me.get('id'),
        me.get('displayName'),
        me_email)

There is anothere way mentioned to use own decoder, but dont't know how to do that, please help me.

Marcel Hinderlich
  • 213
  • 1
  • 3
  • 19

1 Answers1

0

I figured out some dirty workaround using simplejson module (also got a loads method so nothing to change here)

importing that as

import simplejson as json

before Google class lets the authentification work as expected

Marcel Hinderlich
  • 213
  • 1
  • 3
  • 19