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: :param uri: The authorize endpoint to fetch "code"
(
uri, client_id, response_type, redirect_uri=None, scope=None, state=None, **kwargs
)
| 11 | |
| 12 | |
| 13 | def prepare_grant_uri( |
| 14 | uri, client_id, response_type, redirect_uri=None, scope=None, state=None, **kwargs |
| 15 | ): |
| 16 | """Prepare the authorization grant request URI. |
| 17 | |
| 18 | The client constructs the request URI by adding the following |
| 19 | parameters to the query component of the authorization endpoint URI |
| 20 | using the ``application/x-www-form-urlencoded`` format: |
| 21 | |
| 22 | :param uri: The authorize endpoint to fetch "code" or "token". |
| 23 | :param client_id: The client identifier as described in `Section 2.2`_. |
| 24 | :param response_type: To indicate which OAuth 2 grant/flow is required, |
| 25 | "code" and "token". |
| 26 | :param redirect_uri: The client provided URI to redirect back to after |
| 27 | authorization as described in `Section 3.1.2`_. |
| 28 | :param scope: The scope of the access request as described by |
| 29 | `Section 3.3`_. |
| 30 | :param state: An opaque value used by the client to maintain |
| 31 | state between the request and callback. The authorization |
| 32 | server includes this value when redirecting the user-agent |
| 33 | back to the client. The parameter SHOULD be used for |
| 34 | preventing cross-site request forgery as described in |
| 35 | `Section 10.12`_. |
| 36 | :param kwargs: Extra arguments to embed in the grant/authorization URL. |
| 37 | |
| 38 | An example of an authorization code grant authorization URL:: |
| 39 | |
| 40 | /authorize?response_type=code&client_id=s6BhdRkqt3&state=xyz |
| 41 | &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb |
| 42 | |
| 43 | .. _`Section 2.2`: https://tools.ietf.org/html/rfc6749#section-2.2 |
| 44 | .. _`Section 3.1.2`: https://tools.ietf.org/html/rfc6749#section-3.1.2 |
| 45 | .. _`Section 3.3`: https://tools.ietf.org/html/rfc6749#section-3.3 |
| 46 | .. _`section 10.12`: https://tools.ietf.org/html/rfc6749#section-10.12 |
| 47 | """ |
| 48 | params = [("response_type", response_type), ("client_id", client_id)] |
| 49 | |
| 50 | if redirect_uri: |
| 51 | params.append(("redirect_uri", redirect_uri)) |
| 52 | if scope: |
| 53 | params.append(("scope", list_to_scope(scope))) |
| 54 | if state: |
| 55 | params.append(("state", state)) |
| 56 | |
| 57 | for k, value in kwargs.items(): |
| 58 | if value is not None: |
| 59 | if isinstance(value, (list, tuple)): |
| 60 | for v in value: |
| 61 | if v is not None: |
| 62 | params.append((to_unicode(k), v)) |
| 63 | else: |
| 64 | params.append((to_unicode(k), value)) |
| 65 | |
| 66 | return add_params_to_uri(uri, params) |
| 67 | |
| 68 | |
| 69 | def prepare_token_request(grant_type, body="", redirect_uri=None, **kwargs): |
no test coverage detected
searching dependent graphs…