How to use the oauthlib.common.unicode_type function in oauthlib

To help you get started, we’ve selected a few oauthlib 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 filiph / progress_bar / gae / oauthlib / oauth2 / rfc6749 / utils.py View on Github external
def scope_to_list(scope):
    """Convert a space separated string to a list of scopes."""
    if isinstance(scope, list):
        return [unicode_type(s) for s in scope]
    if isinstance(scope, set):
        scope_to_list(list(scope))
    elif scope is None:
        return None
    else:
        return scope.strip().split(" ")
github pymedusa / Medusa / ext / oauthlib / oauth2 / rfc6749 / parameters.py View on Github external
.. _`Section 1.4`: https://tools.ietf.org/html/rfc6749#section-1.4
    .. _`Section 1.5`: https://tools.ietf.org/html/rfc6749#section-1.5
    .. _`Section 4.1.2`: https://tools.ietf.org/html/rfc7009#section-4.1.2

    """
    if not is_secure_transport(url):
        raise InsecureTransportError()

    params = [('token', token)]

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

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

    headers = {'Content-Type': 'application/x-www-form-urlencoded'}

    if callback:
        params.append(('callback', callback))
        return add_params_to_uri(url, params), headers, body
    else:
        return url, headers, add_params_to_qs(body, params)
github oauthlib / oauthlib / oauthlib / oauth2 / rfc6749 / utils.py View on Github external
def list_to_scope(scope):
    """Convert a list of scopes to a space separated string."""
    if isinstance(scope, unicode_type) or scope is None:
        return scope
    elif isinstance(scope, (set, tuple, list)):
        return " ".join([unicode_type(s) for s in scope])
    else:
        raise ValueError("Invalid scope (%s), must be string, tuple, set, or list." % scope)
github filiph / progress_bar / gae / oauthlib / oauth1 / rfc5849 / signature.py View on Github external
"""**RSA-SHA1**

    Per `section 3.4.3`_ of the spec.

    The "RSA-SHA1" signature method uses the RSASSA-PKCS1-v1_5 signature
    algorithm as defined in `RFC3447, Section 8.2`_ (also known as
    PKCS#1), using SHA-1 as the hash function for EMSA-PKCS1-v1_5.  To
    use this method, the client MUST have established client credentials
    with the server that included its RSA public key (in a manner that is
    beyond the scope of this specification).

    .. _`section 3.4.3`: http://tools.ietf.org/html/rfc5849#section-3.4.3
    .. _`RFC3447, Section 8.2`: http://tools.ietf.org/html/rfc3447#section-8.2

    """
    if isinstance(base_string, unicode_type):
        base_string = base_string.encode('utf-8')
    # TODO: finish RSA documentation
    alg = _jwt_rs1_signing_algorithm()
    key = _prepare_key_plus(alg, rsa_private_key)
    s=alg.sign(base_string, key)
    return binascii.b2a_base64(s)[:-1].decode('utf-8')
github nsfmc / Stumblr / oauthlib / oauth1 / rfc5849 / utils.py View on Github external
def unescape(u):
    if not isinstance(u, unicode_type):
        raise ValueError('Only unicode objects are unescapable.')
    return unquote(u)
github oauthlib / oauthlib / oauthlib / oauth2 / rfc6749 / tokens.py View on Github external
if draft == 0:
        base.append(nonce)
    else:
        base.append(ts)
        base.append(nonce)
    base.append(http_method.upper())
    base.append(request_uri)
    base.append(host)
    base.append(port)
    if draft == 0:
        base.append(bodyhash)
    base.append(ext or '')
    base_string = '\n'.join(base) + '\n'

    # hmac struggles with unicode strings - http://bugs.python.org/issue5285
    if isinstance(key, unicode_type):
        key = key.encode('utf-8')
    sign = hmac.new(key, base_string.encode('utf-8'), h)
    sign = b2a_base64(sign.digest())[:-1].decode('utf-8')

    header = []
    header.append('MAC id="%s"' % token)
    if draft != 0:
        header.append('ts="%s"' % ts)
    header.append('nonce="%s"' % nonce)
    if bodyhash:
        header.append('bodyhash="%s"' % bodyhash)
    if ext:
        header.append('ext="%s"' % ext)
    header.append('mac="%s"' % sign)

    headers = headers or {}
github oauthlib / oauthlib / oauthlib / oauth2 / rfc6749 / utils.py View on Github external
def list_to_scope(scope):
    """Convert a list of scopes to a space separated string."""
    if isinstance(scope, unicode_type) or scope is None:
        return scope
    elif isinstance(scope, (set, tuple, list)):
        return " ".join([unicode_type(s) for s in scope])
    else:
        raise ValueError("Invalid scope (%s), must be string, tuple, set, or list." % scope)
github filiph / progress_bar / gae / oauthlib / oauth2 / rfc6749 / utils.py View on Github external
def list_to_scope(scope):
    """Convert a list of scopes to a space separated string."""
    if isinstance(scope, unicode_type) or scope is None:
        return scope
    elif isinstance(scope, (tuple, list)):
        return " ".join([unicode_type(s) for s in scope])
    elif isinstance(scope, set):
        return list_to_scope(list(scope))
    else:
        raise ValueError("Invalid scope, must be string or list.")
github pymedusa / Medusa / ext / oauthlib / oauth1 / rfc5849 / signature.py View on Github external
Host: EXAMPLE.COM:80

    is represented by the base string URI: "http://example.com/r%20v/X".

    In another example, the HTTPS request::

        GET /?q=1 HTTP/1.1
        Host: www.example.net:8080

    is represented by the base string URI: "https://www.example.net:8080/".

    .. _`section 3.4.1.2`: https://tools.ietf.org/html/rfc5849#section-3.4.1.2

    The host argument overrides the netloc part of the uri argument.
    """
    if not isinstance(uri, unicode_type):
        raise ValueError('uri must be a unicode object.')

    # FIXME: urlparse does not support unicode
    scheme, netloc, path, params, query, fragment = urlparse.urlparse(uri)

    # The scheme, authority, and path of the request resource URI `RFC3986`
    # are included by constructing an "http" or "https" URI representing
    # the request resource (without the query or fragment) as follows:
    #
    # .. _`RFC3986`: https://tools.ietf.org/html/rfc3986

    if not scheme or not netloc:
        raise ValueError('uri must include a scheme and netloc')

    # Per `RFC 2616 section 5.1.2`_:
    #
github h3llrais3r / Auto-Subliminal / lib / oauthlib / oauth2 / rfc6749 / parameters.py View on Github external
# pull the `client_id` out of the kwargs. 
    client_id = kwargs.pop('client_id', None)
    if include_client_id:
        if client_id is not None:
            params.append((unicode_type('client_id'), client_id))

    # the kwargs iteration below only supports including boolean truth (truthy)
    # values, but some servers may require an empty string for `client_secret`
    client_secret = kwargs.pop('client_secret', None)
    if client_secret is not None:
        params.append((unicode_type('client_secret'), client_secret))

    # this handles: `code`, `redirect_uri`, and other undocumented params
    for k in kwargs:
        if kwargs[k]:
            params.append((unicode_type(k), kwargs[k]))

    return add_params_to_qs(body, params)