summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJonathan Huot <jonathan.huot@gmail.com>2019-10-25 11:28:51 +0200
committerJonathan Huot <jonathan.huot@gmail.com>2019-10-25 11:28:51 +0200
commitf68ec220d9ff5ec8e710d3e916318dad0de3e2d2 (patch)
tree25e488531d322c50aedecdd836a40f8888b3ecf3 /docs
parent842f5da2702ad76bb043c48ad5726da754277828 (diff)
downloadoauthlib-f68ec220d9ff5ec8e710d3e916318dad0de3e2d2.tar.gz
Add custom grant example
Diffstat (limited to 'docs')
-rw-r--r--docs/oauth2/grants/custom_grant.rst26
1 files changed, 20 insertions, 6 deletions
diff --git a/docs/oauth2/grants/custom_grant.rst b/docs/oauth2/grants/custom_grant.rst
index ba5446c..7408cf6 100644
--- a/docs/oauth2/grants/custom_grant.rst
+++ b/docs/oauth2/grants/custom_grant.rst
@@ -1,5 +1,6 @@
+=================
Custom Grant type
------------------
+=================
Writing a custom grant type can be useful to implement a specification
which is in an early draft, or implement a grant provided by a
@@ -38,12 +39,25 @@ for examples.
3. Example
----------
-To be completed.
+Sample below shows the creation of a new custom `grant_type` parameter
+and declare it in the `/token` endpoint of your `Server`. Note that
+you can reuse `pre_configured.Server` or use your own class inheriting
+of the `Endpoint` classes you have decided.
.. code-block:: python
- class XXXZZZGrant(GrantTypeBase):
+
+ class MyCustomGrant(GrantTypeBase):
def create_token_response(self, request, token_handler):
- if not request.grant_type == 'xxx_zzz':
+ if not request.grant_type == 'urn:ietf:params:oauth:grant-type:my-custom-grant':
raise errors.UnsupportedGrantTypeError(request=request)
- ...
-
+ # implement your custom validation checks
+ # ..
+
+ token = token_handler.create_token(request,
+ refresh_token=self.issue_new_refresh_tokens)
+ return self._get_default_headers(), json.dumps(token), 200
+
+ def setup_oauthlib():
+ my_custom_grant = MyCustomGrant()
+ server = Server(request_validator)
+ server.grant_types["urn:ietf:params:oauth:grant-type:my-custom-grant"] = my_custom_grant