當前位置: 首頁>>代碼示例>>Python>>正文


Python common.add_params_to_uri方法代碼示例

本文整理匯總了Python中oauthlib.common.add_params_to_uri方法的典型用法代碼示例。如果您正苦於以下問題:Python common.add_params_to_uri方法的具體用法?Python common.add_params_to_uri怎麽用?Python common.add_params_to_uri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在oauthlib.common的用法示例。


在下文中一共展示了common.add_params_to_uri方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: linkedin_compliance_fix

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def linkedin_compliance_fix(session):

    def _missing_token_type(r):
        token = loads(r.text)
        token['token_type'] = 'Bearer'
        r._content = to_unicode(dumps(token)).encode('UTF-8')
        return r

    def _non_compliant_param_name(url, headers, data):
        token = [('oauth2_access_token', session.access_token)]
        url = add_params_to_uri(url, token)
        return url, headers, data

    session._client.default_token_placement = 'query'
    session.register_compliance_hook('access_token_response',
                                     _missing_token_type)
    session.register_compliance_hook('protected_request',
                                     _non_compliant_param_name)
    return session 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:21,代碼來源:linkedin.py

示例2: create_session

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def create_session(self, scope: list = None, prompt: bool = True, params: dict = None):
        """Primary method used to create OAuth2 session and redirect users for
        authorization code grant.

        Parameters
        ----------
        scope : list, optional
            An optional list of valid `Discord OAuth2 Scopes
            <https://discordapp.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes>`_.
        prompt : bool, optional
            Determines if the OAuth2 grant should be explicitly prompted and re-approved. Defaults to True.
            Specify False for implicit grant which will skip the authorization screen and redirect to redirect URI.
        params : dict, optional
            An optional mapping of query parameters to supply to the authorization URL.

        Returns
        -------
        redirect
            Flask redirect to discord authorization servers to complete authorization code grant process.

        """
        scope = scope or request.args.get("scope", str()).split() or configs.DISCORD_OAUTH_DEFAULT_SCOPES

        if not prompt and set(scope) & set(configs.DISCORD_PASSTHROUGH_SCOPES):
            raise ValueError("You should use explicit OAuth grant for passthrough scopes like bot.")

        discord_session = self._make_session(scope=scope)
        authorization_url, state = discord_session.authorization_url(configs.DISCORD_AUTHORIZATION_BASE_URL)
        session["DISCORD_OAUTH2_STATE"] = state

        prompt = "consent" if prompt else "none"
        params = params or dict()
        params.update(prompt=prompt)
        authorization_url = add_params_to_uri(authorization_url, params)

        return redirect(authorization_url) 
開發者ID:thec0sm0s,項目名稱:Flask-Discord,代碼行數:38,代碼來源:client.py

示例3: create_authorization_response

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def create_authorization_response(self):
        def decorator(f):
            @functools.wraps(f)
            def wrapper(*args, **kwargs):
                assert self._oauthlib, "BottleOAuth2 not initialized with OAuthLib"

                uri, http_method, body, headers = extract_params(bottle.request)
                scope = bottle.request.params.get('scope', '').split(' ')

                try:
                    resp_headers, resp_body, resp_status = self._oauthlib.create_authorization_response(
                        uri, http_method=http_method, body=body, headers=headers, scopes=scope
                    )
                except FatalClientError as e:
                    if self._error_uri:
                        raise bottle.HTTPResponse(status=302, headers={"Location": add_params_to_uri(
                            self._error_uri, {'error': e.error, 'error_description': e.description}
                        )})
                    raise e
                except OAuth2Error as e:
                    resp_headers, resp_body, resp_status = e.headers, e.json, e.status_code
                set_response(bottle.request, bottle.response, resp_status, resp_headers, resp_body)

                func_response = f(*args, **kwargs)
                if func_response:
                    return func_response
                return bottle.response
            return wrapper
        return decorator 
開發者ID:Refinitiv,項目名稱:bottle-oauthlib,代碼行數:31,代碼來源:oauth2.py

示例4: slack_compliance_fix

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def slack_compliance_fix(session):
    def _non_compliant_param_name(url, headers, data):
        # If the user has already specified the token, either in the URL
        # or in a data dictionary, then there's nothing to do.
        # If the specified token is different from ``session.access_token``,
        # we assume the user intends to override the access token.
        url_query = dict(parse_qs(urlparse(url).query))
        token = url_query.get("token")
        if not token and isinstance(data, dict):
            token = data.get("token")

        if token:
            # Nothing to do, just return.
            return url, headers, data

        if not data:
            data = {"token": session.access_token}
        elif isinstance(data, dict):
            data["token"] = session.access_token
        else:
            # ``data`` is something other than a dict: maybe a stream,
            # maybe a file object, maybe something else. We can't easily
            # modify it, so we'll set the token by modifying the URL instead.
            token = [('token', session.access_token)]
            url = add_params_to_uri(url, token)
        return url, headers, data

    session.register_compliance_hook('protected_request', _non_compliant_param_name)
    return session 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:31,代碼來源:slack.py

示例5: in_uri

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def in_uri(self, uri):
        return add_params_to_uri(uri, self.twotuples) 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:4,代碼來源:errors.py

示例6: prepare_bearer_uri

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def prepare_bearer_uri(token, uri):
    """Add a `Bearer Token`_ to the request URI.
    Not recommended, use only if client can't use authorization header or body.

    http://www.example.com/path?access_token=h480djs93hd8

    .. _`Bearer Token`: https://tools.ietf.org/html/rfc6750
    """
    return add_params_to_uri(uri, [(('access_token', token))]) 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:11,代碼來源:tokens.py

示例7: prepare_authorization_response

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def prepare_authorization_response(self, request, token, headers, body, status):
        """Place token according to response mode.

        Base classes can define a default response mode for their authorization
        response by overriding the static `default_response_mode` member.
        """
        request.response_mode = request.response_mode or self.default_response_mode

        if request.response_mode not in ('query', 'fragment'):
            log.debug('Overriding invalid response mode %s with %s',
                      request.response_mode, self.default_response_mode)
            request.response_mode = self.default_response_mode

        token_items = token.items()

        if request.response_type == 'none':
            state = token.get('state', None)
            if state:
                token_items = [('state', state)]
            else:
                token_items = []

        if request.response_mode == 'query':
            headers['Location'] = add_params_to_uri(
                request.redirect_uri, token_items, fragment=False)
            return headers, body, status

        if request.response_mode == 'fragment':
            headers['Location'] = add_params_to_uri(
                request.redirect_uri, token_items, fragment=True)
            return headers, body, status

        raise NotImplementedError(
            'Subclasses must set a valid default_response_mode') 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:36,代碼來源:base.py

示例8: in_uri

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def in_uri(self, uri):
        fragment = self.response_mode == "fragment"
        return add_params_to_uri(uri, self.twotuples, fragment) 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:5,代碼來源:errors.py

示例9: prepare_request

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def prepare_request(uri, headers=None, data=None, method=None):
    """Make request parameters right."""
    if headers is None:
        headers = {}

    if data and not method:
        method = 'POST'
    elif not method:
        method = 'GET'

    if method == 'GET' and data:
        uri = add_params_to_uri(uri, data)
        data = None

    return uri, headers, data, method 
開發者ID:gita,項目名稱:BhagavadGita,代碼行數:17,代碼來源:client.py

示例10: authorize_handler

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def authorize_handler(self, f):
        """Authorization handler decorator.

        This decorator will sort the parameters and headers out, and
        pre validate everything::

            @app.route('/oauth/authorize', methods=['GET', 'POST'])
            @oauth.authorize_handler
            def authorize(*args, **kwargs):
                if request.method == 'GET':
                    # render a page for user to confirm the authorization
                    return render_template('oauthorize.html')

                confirm = request.form.get('confirm', 'no')
                return confirm == 'yes'
        """

        @wraps(f)
        def decorated(*args, **kwargs):
            if request.method == 'POST':
                if not f(*args, **kwargs):
                    uri = add_params_to_uri(self.error_uri,
                                            [('error', 'denied')])
                    return redirect(uri)
                return self.confirm_authorization_request()

            server = self.server

            uri, http_method, body, headers = extract_params()
            try:
                realms, credentials = server.get_realms_and_credentials(
                    uri, http_method=http_method, body=body, headers=headers)
                kwargs['realms'] = realms
                kwargs.update(credentials)
                return f(*args, **kwargs)
            except errors.OAuth1Error as e:
                return redirect(e.in_uri(self.error_uri))
            except errors.InvalidClientError as e:
                return redirect(e.in_uri(self.error_uri))

        return decorated 
開發者ID:gita,項目名稱:BhagavadGita,代碼行數:43,代碼來源:oauth1.py

示例11: prepare_bearer_uri

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def prepare_bearer_uri(token, uri):
    """Add a `Bearer Token`_ to the request URI.
    Not recommended, use only if client can't use authorization header or body.

    http://www.example.com/path?access_token=h480djs93hd8

    .. _`Bearer Token`: http://tools.ietf.org/html/rfc6750
    """
    return add_params_to_uri(uri, [(('access_token', token))]) 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:11,代碼來源:tokens.py

示例12: authorization_url

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def authorization_url(self, url, request_token=None, **kwargs):
        """Create an authorization URL by appending request_token and optional
        kwargs to url.

        This is the second step in the OAuth 1 workflow. The user should be
        redirected to this authorization URL, grant access to you, and then
        be redirected back to you. The redirection back can either be specified
        during client registration or by supplying a callback URI per request.

        :param url: The authorization endpoint URL.
        :param request_token: The previously obtained request token.
        :param kwargs: Optional parameters to append to the URL.
        :returns: The authorization URL with new parameters embedded.

        An example using a registered default callback URI.

        >>> request_token_url = 'https://api.twitter.com/oauth/request_token'
        >>> authorization_url = 'https://api.twitter.com/oauth/authorize'
        >>> oauth_session = OAuth1Session('client-key', client_secret='secret')
        >>> oauth_session.fetch_request_token(request_token_url)
        {
            'oauth_token': 'sdf0o9823sjdfsdf',
            'oauth_token_secret': '2kjshdfp92i34asdasd',
        }
        >>> oauth_session.authorization_url(authorization_url)
        'https://api.twitter.com/oauth/authorize?oauth_token=sdf0o9823sjdfsdf'
        >>> oauth_session.authorization_url(authorization_url, foo='bar')
        'https://api.twitter.com/oauth/authorize?oauth_token=sdf0o9823sjdfsdf&foo=bar'

        An example using an explicit callback URI.

        >>> request_token_url = 'https://api.twitter.com/oauth/request_token'
        >>> authorization_url = 'https://api.twitter.com/oauth/authorize'
        >>> oauth_session = OAuth1Session('client-key', client_secret='secret', callback_uri='https://127.0.0.1/callback')
        >>> oauth_session.fetch_request_token(request_token_url)
        {
            'oauth_token': 'sdf0o9823sjdfsdf',
            'oauth_token_secret': '2kjshdfp92i34asdasd',
        }
        >>> oauth_session.authorization_url(authorization_url)
        'https://api.twitter.com/oauth/authorize?oauth_token=sdf0o9823sjdfsdf&oauth_callback=https%3A%2F%2F127.0.0.1%2Fcallback'
        """
        kwargs['oauth_token'] = request_token or self._client.client.resource_owner_key
        log.debug('Adding parameters %s to url %s', kwargs, url)
        return add_params_to_uri(url, kwargs.items()) 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:47,代碼來源:oauth1_session.py

示例13: prepare_grant_uri

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def prepare_grant_uri(uri, client_id, response_type, redirect_uri=None,
                      scope=None, state=None, **kwargs):
    """Prepare the authorization grant request URI.

    The client constructs the request URI by adding the following
    parameters to the query component of the authorization endpoint URI
    using the ``application/x-www-form-urlencoded`` format as defined by
    [`W3C.REC-html401-19991224`_]:

    :param response_type: To indicate which OAuth 2 grant/flow is required,
                          "code" and "token".
    :param client_id: The client identifier as described in `Section 2.2`_.
    :param redirect_uri: The client provided URI to redirect back to after
                         authorization as described in `Section 3.1.2`_.
    :param scope: The scope of the access request as described by
                  `Section 3.3`_.

    :param state: An opaque value used by the client to maintain
                  state between the request and callback.  The authorization
                  server includes this value when redirecting the user-agent
                  back to the client.  The parameter SHOULD be used for
                  preventing cross-site request forgery as described in
                  `Section 10.12`_.
    :param kwargs: Extra arguments to embed in the grant/authorization URL.

    An example of an authorization code grant authorization URL:

    .. code-block:: http

        GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz
            &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
        Host: server.example.com

    .. _`W3C.REC-html401-19991224`: https://tools.ietf.org/html/rfc6749#ref-W3C.REC-html401-19991224
    .. _`Section 2.2`: https://tools.ietf.org/html/rfc6749#section-2.2
    .. _`Section 3.1.2`: https://tools.ietf.org/html/rfc6749#section-3.1.2
    .. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3
    .. _`section 10.12`: https://tools.ietf.org/html/rfc6749#section-10.12
    """
    if not is_secure_transport(uri):
        raise InsecureTransportError()

    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((unicode_type(k), kwargs[k]))

    return add_params_to_uri(uri, params) 
開發者ID:kylebebak,項目名稱:Requester,代碼行數:59,代碼來源:parameters.py

示例14: prepare_grant_uri

# 需要導入模塊: from oauthlib import common [as 別名]
# 或者: from oauthlib.common import add_params_to_uri [as 別名]
def prepare_grant_uri(uri, client_id, response_type, redirect_uri=None,
                      scope=None, state=None, **kwargs):
    """Prepare the authorization grant request URI.

    The client constructs the request URI by adding the following
    parameters to the query component of the authorization endpoint URI
    using the ``application/x-www-form-urlencoded`` format as defined by
    [`W3C.REC-html401-19991224`_]:

    :param response_type: To indicate which OAuth 2 grant/flow is required,
                          "code" and "token".
    :param client_id: The client identifier as described in `Section 2.2`_.
    :param redirect_uri: The client provided URI to redirect back to after
                         authorization as described in `Section 3.1.2`_.
    :param scope: The scope of the access request as described by
                  `Section 3.3`_.

    :param state: An opaque value used by the client to maintain
                  state between the request and callback.  The authorization
                  server includes this value when redirecting the user-agent
                  back to the client.  The parameter SHOULD be used for
                  preventing cross-site request forgery as described in
                  `Section 10.12`_.
    :param kwargs: Extra arguments to embed in the grant/authorization URL.

    An example of an authorization code grant authorization URL:

    .. code-block:: http

        GET /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz
            &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb HTTP/1.1
        Host: server.example.com

    .. _`W3C.REC-html401-19991224`: http://tools.ietf.org/html/rfc6749#ref-W3C.REC-html401-19991224
    .. _`Section 2.2`: http://tools.ietf.org/html/rfc6749#section-2.2
    .. _`Section 3.1.2`: http://tools.ietf.org/html/rfc6749#section-3.1.2
    .. _`Section 3.3`: http://tools.ietf.org/html/rfc6749#section-3.3
    .. _`section 10.12`: http://tools.ietf.org/html/rfc6749#section-10.12
    """
    if not is_secure_transport(uri):
        raise InsecureTransportError()

    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((unicode_type(k), kwargs[k]))

    return add_params_to_uri(uri, params) 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:59,代碼來源:parameters.py


注:本文中的oauthlib.common.add_params_to_uri方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。