Beispiel #1
0
 def _parse_token(self, response):
     r = response.json_dict()
     if 'error_code' in r:
         raise ApiResponseError(
             response, r.error_code,
             r.get('error_description', r.get('error', '')))
     return Token(**r)
Beispiel #2
0
    def parse_signed_request(self, signed_request):
        """  用于站内应用
        signed_request: 应用框架在加载时会通过向Canvas URL post的参数signed_request
        Returns: Token, is_valid (令牌, 是否有效)
        """
        def base64decode(s):
            appendix = '=' * (4 - len(s) % 4)
            return base64.b64decode(
                s.replace('-', '+').replace('_', '/') + appendix)

        encoded_sign, encoded_data = signed_request.split('.', 1)
        sign = base64decode(encoded_sign)
        data = loads(base64decode(encoded_data))
        token = Token(data.oauth_token,
                      data.expires,
                      uid=data.user_id,
                      created_at=data.issued_at,
                      **data)
        is_valid = data.algorithm == u'HMAC-SHA256' and hmac.new(
            self.app.key, encoded_data, hashlib.sha256).digest() == sign
        return token, is_valid
Beispiel #3
0
 def _parse_token(self, response):
     data = parse_querystring(response.text)
     if 'errorCode' in data:
         raise ApiResponseError(response, data['errorCode'], data.get('errorMsg', '').strip("'"))
     return Token(**data)
Beispiel #4
0
 def __init__(self, app=App(), token=Token(), openid=None, clientip=None):
     super(Client, self).__init__(app, token)
     self.openid = openid
     self.clientip = clientip
Beispiel #5
0
 def _parse_token(self, response):
     data = parse(response)
     data['created_at'] = data.get('create_at', None)
     if 'expires_in' not in data:
         data['expires_in'] = data.get('expire_in', None)
     return Token(**data)
Beispiel #6
0
 def __init__(self, app=App(), session=None):
     super(Client, self).__init__(app, Token(session))
Beispiel #7
0
 def _parse_token(self, response):
     data = parse(response)
     return Token(**data)