How to use the authlib.common.encoding.to_unicode function in Authlib

To help you get started, we’ve selected a few Authlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lepture / authlib / tests / core / test_requests_client / test_oauth1_session.py View on Github external
def fake_send(r, **kwargs):
                signature = to_unicode(getter(r))
                self.assertIn('oauth_signature', signature)
                resp = mock.MagicMock(spec=requests.Response)
                resp.cookies = []
                return resp
            return fake_send
github lepture / authlib / tests / core / test_requests_client / test_oauth1_session.py View on Github external
def fake_send(r, **kwargs):
            auth_header = to_unicode(r.headers['Authorization'])
            self.assertEqual(auth_header, signature)
            resp = mock.MagicMock(spec=requests.Response)
            resp.cookies = []
            return resp
        return fake_send
github lepture / authlib / tests / django / test_oauth1 / test_resource_protector.py View on Github external
auth_header = (
            'OAuth oauth_consumer_key="client",'
            'oauth_signature_method="PLAINTEXT",'
            'oauth_token="valid-token",'
            'oauth_signature="secret&valid-token-secret"'
        )
        request = self.factory.get(url, HTTP_AUTHORIZATION=auth_header)
        resp = handle(request)
        data = json.loads(to_unicode(resp.content))
        self.assertIn('username', data)

        # case 2: invalid signature
        auth_header = auth_header.replace('valid-token-secret', 'invalid')
        request = self.factory.get(url, HTTP_AUTHORIZATION=auth_header)
        resp = handle(request)
        data = json.loads(to_unicode(resp.content))
        self.assertEqual(data['error'], 'invalid_signature')
github lepture / authlib / authlib / oauth2 / rfc6749 / util.py View on Github external
def scope_to_list(scope):
    """Convert a space separated string to a list of scopes."""
    if isinstance(scope, (tuple, list, set)):
        return [to_unicode(s) for s in scope]
    elif scope is None:
        return None
    return scope.strip().split()
github lepture / authlib / authlib / common / urls.py View on Github external
def url_encode(params):
    encoded = []
    for k, v in params:
        encoded.append((to_bytes(k), to_bytes(v)))
    return to_unicode(_urlencode(encoded))
github lepture / authlib / authlib / specs / rfc6749 / parameters.py View on Github external
"""
    params = [
        ('response_type', response_type),
        ('client_id', client_id)
    ]

    if redirect_uri:
        params.append(('redirect_uri', redirect_uri))
    if scope:
        params.append(('scope', list_to_scope(scope)))
    if state:
        params.append(('state', state))

    for k in kwargs:
        if kwargs[k]:
            params.append((to_unicode(k), kwargs[k]))

    return add_params_to_uri(uri, params)
github lepture / authlib / authlib / specs / rfc6749 / parameters.py View on Github external
grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA
        &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb

    .. _`Section 4.1.1`: http://tools.ietf.org/html/rfc6749#section-4.1.1
    """
    params = [('grant_type', grant_type)]

    if redirect_uri:
        params.append(('redirect_uri', redirect_uri))

    if 'scope' in kwargs:
        kwargs['scope'] = list_to_scope(kwargs['scope'])

    for k in kwargs:
        if kwargs[k]:
            params.append((to_unicode(k), kwargs[k]))

    return add_params_to_qs(body, params)
github lepture / authlib / authlib / jose / rfc7515 / jws.py View on Github external
def _sign(jws_header):
            self._validate_header(jws_header)
            _alg, _key = prepare_algorithm_key(
                self._algorithms, jws_header, payload, key, private=True)

            protected_segment = json_b64encode(jws_header.protected)
            signing_input = b'.'.join([protected_segment, payload_segment])
            signature = urlsafe_b64encode(_alg.sign(signing_input, _key))

            rv = {
                'protected': to_unicode(protected_segment),
                'signature': to_unicode(signature)
            }
            if jws_header.header is not None:
                rv['header'] = jws_header.header
            return rv
github lepture / authlib / authlib / integrations / django_helpers.py View on Github external
def _unicode_value(value):
    return to_unicode(value, 'latin-1')