summaryrefslogtreecommitdiff
path: root/oauthlib/oauth2/rfc6749/clients/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'oauthlib/oauth2/rfc6749/clients/base.py')
-rw-r--r--oauthlib/oauth2/rfc6749/clients/base.py155
1 files changed, 65 insertions, 90 deletions
diff --git a/oauthlib/oauth2/rfc6749/clients/base.py b/oauthlib/oauth2/rfc6749/clients/base.py
index bb4c133..6a5d0dc 100644
--- a/oauthlib/oauth2/rfc6749/clients/base.py
+++ b/oauthlib/oauth2/rfc6749/clients/base.py
@@ -228,26 +228,21 @@ class Client:
required parameters to the authorization URL.
:param authorization_url: Provider authorization endpoint URL.
-
:param state: CSRF protection string. Will be automatically created if
- not provided. The generated state is available via the ``state``
- attribute. Clients should verify that the state is unchanged and
- present in the authorization response. This verification is done
- automatically if using the ``authorization_response`` parameter
- with ``prepare_token_request``.
-
+ not provided. The generated state is available via the ``state``
+ attribute. Clients should verify that the state is unchanged and
+ present in the authorization response. This verification is done
+ automatically if using the ``authorization_response`` parameter
+ with ``prepare_token_request``.
:param redirect_url: Redirect URL to which the user will be returned
- after authorization. Must be provided unless previously setup with
- the provider. If provided then it must also be provided in the
- token request.
-
+ after authorization. Must be provided unless previously setup with
+ the provider. If provided then it must also be provided in the
+ token request.
:param scope: List of scopes to request. Must be equal to
- or a subset of the scopes granted when obtaining the refresh
- token. If none is provided, the ones provided in the constructor are
- used.
-
+ or a subset of the scopes granted when obtaining the refresh
+ token. If none is provided, the ones provided in the constructor are
+ used.
:param kwargs: Additional parameters to included in the request.
-
:returns: The prepared request tuple with (url, headers, body).
"""
if not is_secure_transport(authorization_url):
@@ -271,22 +266,16 @@ class Client:
credentials.
:param token_url: Provider token creation endpoint URL.
-
:param authorization_response: The full redirection URL string, i.e.
- the location to which the user was redirected after successfull
- authorization. Used to mine credentials needed to obtain a token
- in this step, such as authorization code.
-
+ the location to which the user was redirected after successfull
+ authorization. Used to mine credentials needed to obtain a token
+ in this step, such as authorization code.
:param redirect_url: The redirect_url supplied with the authorization
- request (if there was one).
-
+ request (if there was one).
:param state:
-
:param body: Existing request body (URL encoded string) to embed parameters
into. This may contain extra paramters. Default ''.
-
:param kwargs: Additional parameters to included in the request.
-
:returns: The prepared request tuple with (url, headers, body).
"""
if not is_secure_transport(token_url):
@@ -312,19 +301,14 @@ class Client:
obtain a new access token, and possibly a new refresh token.
:param token_url: Provider token refresh endpoint URL.
-
:param refresh_token: Refresh token string.
-
:param body: Existing request body (URL encoded string) to embed parameters
- into. This may contain extra paramters. Default ''.
-
+ into. This may contain extra paramters. Default ''.
:param scope: List of scopes to request. Must be equal to
- or a subset of the scopes granted when obtaining the refresh
- token. If none is provided, the ones provided in the constructor are
- used.
-
+ or a subset of the scopes granted when obtaining the refresh
+ token. If none is provided, the ones provided in the constructor are
+ used.
:param kwargs: Additional parameters to included in the request.
-
:returns: The prepared request tuple with (url, headers, body).
"""
if not is_secure_transport(token_url):
@@ -341,20 +325,14 @@ class Client:
"""Prepare a token revocation request.
:param revocation_url: Provider token revocation endpoint URL.
-
:param token: The access or refresh token to be revoked (string).
-
:param token_type_hint: ``"access_token"`` (default) or
- ``"refresh_token"``. This is optional and if you wish to not pass it you
- must provide ``token_type_hint=None``.
-
+ ``"refresh_token"``. This is optional and if you wish to not pass it you
+ must provide ``token_type_hint=None``.
:param body:
-
:param callback: A jsonp callback such as ``package.callback`` to be invoked
- upon receiving the response. Not that it should not include a () suffix.
-
+ upon receiving the response. Not that it should not include a () suffix.
:param kwargs: Additional parameters to included in the request.
-
:returns: The prepared request tuple with (url, headers, body).
Note that JSONP request may use GET requests as the parameters will
@@ -362,7 +340,7 @@ class Client:
An example of a revocation request
- .. code-block: http
+ .. code-block:: http
POST /revoke HTTP/1.1
Host: server.example.com
@@ -373,7 +351,7 @@ class Client:
An example of a jsonp revocation request
- .. code-block: http
+ .. code-block:: http
GET /revoke?token=agabcdefddddafdd&callback=package.myCallback HTTP/1.1
Host: server.example.com
@@ -382,9 +360,9 @@ class Client:
and an error response
- .. code-block: http
+ .. code-block:: javascript
- package.myCallback({"error":"unsupported_token_type"});
+ package.myCallback({"error":"unsupported_token_type"});
Note that these requests usually require client credentials, client_id in
the case for public clients and provider specific authentication
@@ -408,9 +386,10 @@ class Client:
:param body: The response body from the token request.
:param scope: Scopes originally requested. If none is provided, the ones
- provided in the constructor are used.
+ provided in the constructor are used.
:return: Dictionary of token parameters.
- :raises: Warning if scope has changed. OAuth2Error if response is invalid.
+ :raises: Warning if scope has changed. :py:class:`oauthlib.oauth2.errors.OAuth2Error`
+ if response is invalid.
These response are json encoded and could easily be parsed without
the assistance of OAuthLib. However, there are a few subtle issues
@@ -436,7 +415,7 @@ class Client:
If omitted, the authorization server SHOULD provide the
expiration time via other means or document the default value.
- **scope**
+ **scope**
Providers may supply this in all responses but are required to only
if it has changed since the authorization request.
@@ -454,20 +433,16 @@ class Client:
If the authorization server issued a refresh token to the client, the
client makes a refresh request to the token endpoint by adding the
- following parameters using the "application/x-www-form-urlencoded"
+ following parameters using the `application/x-www-form-urlencoded`
format in the HTTP request entity-body:
- grant_type
- REQUIRED. Value MUST be set to "refresh_token".
- refresh_token
- REQUIRED. The refresh token issued to the client.
- scope
- OPTIONAL. The scope of the access request as described by
- Section 3.3. The requested scope MUST NOT include any scope
- not originally granted by the resource owner, and if omitted is
- treated as equal to the scope originally granted by the
- resource owner. Note that if none is provided, the ones provided
- in the constructor are used if any.
+ :param refresh_token: REQUIRED. The refresh token issued to the client.
+ :param scope: OPTIONAL. The scope of the access request as described by
+ Section 3.3. The requested scope MUST NOT include any scope
+ not originally granted by the resource owner, and if omitted is
+ treated as equal to the scope originally granted by the
+ resource owner. Note that if none is provided, the ones provided
+ in the constructor are used if any.
"""
refresh_token = refresh_token or self.refresh_token
scope = self.scope if scope is None else scope
@@ -492,18 +467,21 @@ class Client:
def create_code_verifier(self, length):
"""Create PKCE **code_verifier** used in computing **code_challenge**.
+ See `RFC7636 Section 4.1`_
+
+ :param length: REQUIRED. The length of the code_verifier.
- :param length: REQUIRED. The length of the code_verifier.
+ The client first creates a code verifier, "code_verifier", for each
+ OAuth 2.0 [RFC6749] Authorization Request, in the following manner:
- The client first creates a code verifier, "code_verifier", for each
- OAuth 2.0 [RFC6749] Authorization Request, in the following manner:
+ .. code-block:: text
- code_verifier = high-entropy cryptographic random STRING using the
- unreserved characters [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~"
- from Section 2.3 of [RFC3986], with a minimum length of 43 characters
- and a maximum length of 128 characters.
-
- .. _`Section 4.1`: https://tools.ietf.org/html/rfc7636#section-4.1
+ code_verifier = high-entropy cryptographic random STRING using the
+ unreserved characters [A-Z] / [a-z] / [0-9] / "-" / "." / "_" / "~"
+ from Section 2.3 of [RFC3986], with a minimum length of 43 characters
+ and a maximum length of 128 characters.
+
+ .. _`RFC7636 Section 4.1`: https://tools.ietf.org/html/rfc7636#section-4.1
"""
code_verifier = None
@@ -525,33 +503,30 @@ class Client:
def create_code_challenge(self, code_verifier, code_challenge_method=None):
"""Create PKCE **code_challenge** derived from the **code_verifier**.
+ See `RFC7636 Section 4.2`_
- :param code_verifier: REQUIRED. The **code_verifier** generated from create_code_verifier().
- :param code_challenge_method: OPTIONAL. The method used to derive the **code_challenge**. Acceptable
- values include "S256". DEFAULT is "plain".
-
+ :param code_verifier: REQUIRED. The **code_verifier** generated from `create_code_verifier()`.
+ :param code_challenge_method: OPTIONAL. The method used to derive the **code_challenge**. Acceptable values include `S256`. DEFAULT is `plain`.
- The client then creates a code challenge derived from the code
+ The client then creates a code challenge derived from the code
verifier by using one of the following transformations on the code
- verifier:
-
- plain
- code_challenge = code_verifier
+ verifier::
- S256
- code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
+ plain
+ code_challenge = code_verifier
+ S256
+ code_challenge = BASE64URL-ENCODE(SHA256(ASCII(code_verifier)))
- If the client is capable of using "S256", it MUST use "S256", as
- "S256" is Mandatory To Implement (MTI) on the server. Clients are
- permitted to use "plain" only if they cannot support "S256" for some
+ If the client is capable of using `S256`, it MUST use `S256`, as
+ `S256` is Mandatory To Implement (MTI) on the server. Clients are
+ permitted to use `plain` only if they cannot support `S256` for some
technical reason and know via out-of-band configuration that the
- server supports "plain".
+ server supports `plain`.
The plain transformation is for compatibility with existing
- deployments and for constrained environments that can't use the S256
- transformation.
+ deployments and for constrained environments that can't use the S256 transformation.
- .. _`Section 4.2`: https://tools.ietf.org/html/rfc7636#section-4.2
+ .. _`RFC7636 Section 4.2`: https://tools.ietf.org/html/rfc7636#section-4.2
"""
code_challenge = None