Skip to content

Commit 85128df

Browse files
author
Massimiliano
committed
docs for custom Application, close #45
1 parent 665d99d commit 85128df

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

docs/extending_application.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Extending the Application model
2+
===============================
3+
4+
An Application instance represents a :term:`Client` on the :term:`Authorization server`. Usually an Application is
5+
issued to client's developers after they log in on an Authorization Server and pass in some data
6+
which identify the Application itself (let's say, the application name). Django OAuth Toolkit
7+
provides a very basic implementation of the Application model containing only the data strictly
8+
required during all the OAuth processes but you will likely need some extra info, like application
9+
logo, acceptance of some user agreement and so on.
10+
11+
.. class:: AbstractApplication(models.Model)
12+
13+
This is the base class implementing the bare minimum for Django OAuth Toolkit to work
14+
15+
* :attr:`client_id` The client identifier issued to the client during the registration process as described in :rfc:`2.2`
16+
* :attr:`user` ref to a Django user
17+
* :attr:`redirect_uris` The list of allowed redirect uri. The string consists of valid URLs separated by space
18+
* :attr:`client_type` Client type as described in :rfc:`2.1`
19+
* :attr:`authorization_grant_type` Authorization flows available to the Application
20+
* :attr:`client_secret` Confidential secret issued to the client during the registration process as described in :rfc:`2.2`
21+
* :attr:`name` Friendly name for the Application
22+
23+
Django OAuth Toolkit lets you extend the AbstractApplication model in a fashion like Django's
24+
custom user models.
25+
26+
If you need, let's say, application logo and user agreement acceptance field, you can to this in
27+
your Django app (provided that your app is in the list of the INSTALLED_APPS in your settings
28+
module)::
29+
30+
from django.db import models
31+
from oauth2_provider import AbstractApplication
32+
33+
class MyApplication(AbstractApplication):
34+
logo = models.ImageField()
35+
agree = models.BooleanField()
36+
37+
Then you need to tell Django OAuth Toolkit which model you want to use to represent applications.
38+
Write something like this in your settings module::
39+
40+
OAUTH2_PROVIDER = {
41+
'APPLICATION_MODEL': 'your_app_name.MyApplication',
42+
}
43+
That's all, now Django OAuth Toolkit will use your model wherever an Application instance is needed.

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Index
3434
tutorial/tutorial
3535
rest-framework/rest-framework
3636
views/views
37+
extending_application
3738
settings
3839

3940
.. toctree::

0 commit comments

Comments
 (0)