Updated packages and code to python3. Won't work with python 2
[twitter-api-cdsw] / oauthlib / oauth2 / rfc6749 / clients / backend_application.py
1 # -*- coding: utf-8 -*-
2 """
3 oauthlib.oauth2.rfc6749
4 ~~~~~~~~~~~~~~~~~~~~~~~
5
6 This module is an implementation of various logic needed
7 for consuming and providing OAuth 2.0 RFC6749.
8 """
9 from __future__ import absolute_import, unicode_literals
10
11 from .base import Client
12 from ..parameters import prepare_token_request
13 from ..parameters import parse_token_response
14
15
16 class BackendApplicationClient(Client):
17
18     """A public client utilizing the client credentials grant workflow.
19
20     The client can request an access token using only its client
21     credentials (or other supported means of authentication) when the
22     client is requesting access to the protected resources under its
23     control, or those of another resource owner which has been previously
24     arranged with the authorization server (the method of which is beyond
25     the scope of this specification).
26
27     The client credentials grant type MUST only be used by confidential
28     clients.
29
30     Since the client authentication is used as the authorization grant,
31     no additional authorization request is needed.
32     """
33
34     def prepare_request_body(self, body='', scope=None, **kwargs):
35         """Add the client credentials to the request body.
36
37         The client makes a request to the token endpoint by adding the
38         following parameters using the "application/x-www-form-urlencoded"
39         format per `Appendix B`_ in the HTTP request entity-body:
40
41         :param scope:   The scope of the access request as described by
42                         `Section 3.3`_.
43         :param kwargs:  Extra credentials to include in the token request.
44
45         The client MUST authenticate with the authorization server as
46         described in `Section 3.2.1`_.
47
48         The prepared body will include all provided credentials as well as
49         the ``grant_type`` parameter set to ``client_credentials``::
50
51             >>> from oauthlib.oauth2 import BackendApplicationClient
52             >>> client = BackendApplicationClient('your_id')
53             >>> client.prepare_request_body(scope=['hello', 'world'])
54             'grant_type=client_credentials&scope=hello+world'
55
56         .. _`Appendix B`: http://tools.ietf.org/html/rfc6749#appendix-B
57         .. _`Section 3.3`: http://tools.ietf.org/html/rfc6749#section-3.3
58         .. _`Section 3.2.1`: http://tools.ietf.org/html/rfc6749#section-3.2.1
59         """
60         return prepare_token_request('client_credentials', body=body,
61                                      scope=scope, **kwargs)

Benjamin Mako Hill || Want to submit a patch?