litl / rauth

A Python library for OAuth 1.0/a, 2.0, and Ofly.
http://readthedocs.org/docs/rauth/en/latest/
MIT License
1.6k stars 175 forks source link

GooglePlus decoder needed #176

Open DavidHwu opened 9 years ago

DavidHwu commented 9 years ago

I believe the default decoder provided by RAuth.utils is incompatible with GooglePlus via OAuth2 decoding schema. Default RAuth decoder when used by GooglePlus, results in an empty dict {}.

I used this following decoder which seems to work just fine as I passed this into RAuth's get_auth_session() and got the desired tokens.

@staticmethod
def decoder(data: bytes, encoding: str='utf-8') -> dict:
    """
    Provide a decoder for RAuth to invoke to unpack the response and decode accordingly

    :param data: bytes
        Byte data stream that needs to be decoded (handled by this decoder)
    :param encoding: str
        Encoding for the bytes

    :return:
        Dictionary with the values returned by Google Plus

    :rtype: dict
    """
    result = data.decode(encoding)
    if result:
        json = loads(result)
        return json
    else:
        return {}
josuebrunel commented 9 years ago

Seems to be the same for Yahoo OAuth2. I will try this one and keep you posted