Skip to content

Commit 34312d0

Browse files
author
joepeg
committed
Update tutorial_01.rst
1 parent 546bce0 commit 34312d0

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

docs/tutorial/tutorial_01.rst

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
Part 1 - make a provider in a minute
1+
Part 1 - Make a Provider in a Minute
22
====================================
33

44
Scenario
55
--------
6-
You want to make your own :term:`Authorization Server`, managing the client applications which will have access to a
7-
certain API, releasing the tokens and so on...
6+
You want to make your own :term:`Authorization Server` to issue access tokens to client applications for a certain API.
87

9-
Start your app
8+
Start Your App
109
--------------
11-
During this tutorial you will make and XHR POST from an Heroku deployed app to your localhost instance.
12-
To achieve this operation you need a properly configured Django server with `django-cors-headers` app installed, since
13-
the domain that originated the request (the app on Heroku) is different from the destination domain (your local instance).
14-
Such "cross-domain" requests are by default forbidden by web browsers unless you use CORS.
15-
You can read more about `CORS here <http://en.wikipedia.org/wiki/Cross-origin_resource_sharing>`_.
10+
During this tutorial you will make an XHR POST from a Heroku deployed app to your localhost instance.
11+
Since the domain that will originate the request (the app on Heroku) is different than the destination domain (your local instance),
12+
you will need to install the `django-cors-headers <https://github.com/ottoyiu/django-cors-headers>`_ app.
13+
These "cross-domain" requests are by default forbidden by web browsers unless you use `CORS <http://en.wikipedia.org/wiki/Cross-origin_resource_sharing>`_.
1614

1715
Create a virtualenv and install `django-oauth-toolkit` and `django-cors-headers`:
1816

1917
::
2018

2119
pip install django-oauth-toolkit django-cors-headers
2220

23-
start a Django project, add `oauth2_provider` and `corsheaders` to the installed apps, enable the admin.
21+
Start a Django project, add `oauth2_provider` and `corsheaders` to the installed apps, and enable admin:
2422

2523
.. code-block:: python
2624
@@ -31,7 +29,7 @@ start a Django project, add `oauth2_provider` and `corsheaders` to the installed
3129
'corsheaders',
3230
}
3331
34-
Include the Django OAuth Toolkit urls in your `urls.py`, choose the urlspace you prefer, for example:
32+
Include the Django OAuth Toolkit urls in your `urls.py`, choosing the urlspace you prefer. For example:
3533

3634
.. code-block:: python
3735
@@ -42,7 +40,7 @@ Include the Django OAuth Toolkit urls in your `urls.py`, choose the urlspace you
4240
# ...
4341
)
4442
45-
Include this middleware in your `settings.py`:
43+
Include the CORS middleware in your `settings.py`:
4644

4745
.. code-block:: python
4846
@@ -52,7 +50,7 @@ Include this middleware in your `settings.py`:
5250
# ...
5351
)
5452
55-
Configure this setting to allow CORS requests from all domains (just for the scope of this tutorial):
53+
Allow CORS requests from all domains (just for the scope of this tutorial):
5654

5755
.. code-block:: python
5856
@@ -62,30 +60,31 @@ Configure this setting to allow CORS requests from all domains (just for the sco
6260

6361
Include the required hidden input in your login template, `registration/login.html`.
6462
The ``{{ next }}`` template context variable will be populated with the correct
65-
redirect value. Django provides more information on `login templates here
66-
<https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.login>`_.
63+
redirect value. See the `Django documentation <https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.views.login>`_
64+
for details on using login templates.
6765

6866
.. code-block:: html
6967

7068
<input type="hidden" name="next" value="{{ next }}" />
7169

72-
As a final step, make a syncdb, start the internal server and login with your credentials.
70+
As a final step, execute syncdb, start the internal server, and login with your credentials.
7371

7472
Create an OAuth2 Client Application
7573
-----------------------------------
76-
An application which wants to perform API requests must be registered in the :term:`Authorization Server` to be properly
77-
identified. This operation is usually done manually by a developer, who asks for an account in the
78-
:term:`Authorization Server` and gets access to some sort of backoffice where she can register her application, which
79-
will act as a :term:`Client` (or :term:`Application` in the Django OAuth Toolkit lingo).
80-
Let's perform exactly this operation.
81-
Point your browser to `http://localhost:8000/o/applications/` and add an Application instance.
74+
Before your :term:`Application` can use the :term:`Authorization Server` for user login,
75+
you must first register the app (also known as the :term:`Client`.) Once registered, your app will be granted access to
76+
the API, subject to approval by its users.
77+
78+
Let's register your application.
79+
80+
Point your browser to http://localhost:8000/o/applications/ and add an Application instance.
8281
`Client id` and `Client Secret` are automatically generated, you have to provide the rest of the informations:
8382

84-
* `User`: the owner of the Application (tipically a developer), could be the current logged in user.
83+
* `User`: the owner of the Application (e.g. a developer, or the currently logged in user.)
8584

86-
* `Redirect uris`: at a certain point of the token request process, the :term:`Authorization Server` needs to know a
87-
list of url (must be at least one) in the client application service where delivering the :term:`Authorization Token`.
88-
Developers have the responsibility to correctly provide this value. For this tutorial, paste verbatim the value
85+
* `Redirect uris`: Applications must register at least one redirection endpoint prior to utilizing the
86+
authorization endpoint. The :term:`Authorization Server` will deliver the access token to the client only if the client
87+
specifies one of the verified redirection uris. For this tutorial, paste verbatim the value
8988
`http://django-oauth-toolkit.herokuapp.com/consumer/exchange/`
9089

9190
* `Client type`: this value affects the security level at which some communications between the client application and
@@ -99,28 +98,28 @@ Point your browser to `http://localhost:8000/o/applications/` and add an Applica
9998
Take note of the `Client id` and the `Client Secret` then logout (this is needed only for testing the authorization
10099
process we'll explain shortly)
101100

102-
Test your authorization server
101+
Test Your Authorization Server
103102
------------------------------
104-
Your authorization server is ready and can start releasing access tokens. To test the process you need an OAuth2
105-
consumer: if you know OAuth2 enough you can use curl, requests or anything can speak http. For the rest of us, we have
106-
a `consumer service <http://django-oauth-toolkit.herokuapp.com/consumer/>`_ deployed on Heroku you can use to test your
107-
provider.
103+
Your authorization server is ready and can begin issuing access tokens. To test the process you need an OAuth2
104+
consumer; if you are familiar enough with OAuth2, you can use curl, requests, or anything that speaks http. For the rest
105+
of us, there is a `consumer service <http://django-oauth-toolkit.herokuapp.com/consumer/>`_ deployed on Heroku to test
106+
your provider.
108107

109-
Build an authorization link for your users
108+
Build an Authorization Link for Your Users
110109
++++++++++++++++++++++++++++++++++++++++++
111-
The process of authorizing an application to access OAuth2 protected data in an :term:`Authorization Code` flow is always
112-
started by the user. You have to prompt your users with a special link they click to start the process. Go to the
113-
`Consumer <http://django-oauth-toolkit.herokuapp.com/consumer/>`_ page and fill the form with the data of the
114-
application you created earlier on this tutorial. Submit the form, you'll get the link your users should follow to get
115-
to the authorization page.
110+
Authorizing an application to access OAuth2 protected data in an :term:`Authorization Code` flow is always initiated
111+
by the user. Your application can prompt users to click a special link to start the process. Go to the
112+
`Consumer <http://django-oauth-toolkit.herokuapp.com/consumer/>`_ page and complete the form by filling in your
113+
application's details obtained from the steps in this tutorial. Submit the form, and you'll receive a link your users can
114+
use to access the authorization page.
116115

117-
Authorize the application
116+
Authorize the Application
118117
+++++++++++++++++++++++++
119-
When the user clicks the link, she is redirected to your (possibly local) :term:`Authorization Server`.
120-
If you're not logged in, at this point you should be prompted for username and password. This is because the authorization
121-
page is login protected by django-oauth-toolkit. Login, then you should see the not so cute form user can use to give
118+
When a user clicks the link, she is redirected to your (possibly local) :term:`Authorization Server`.
119+
If you're not logged in, you will be prompted for username and password. This is because the authorization
120+
page is login protected by django-oauth-toolkit. Login, then you should see the not so cute form users can use to give
122121
her authorization to the client application. Flag the *Allow* checkbox and click *Authorize*, you will be redirected
123-
again on the consumer service.
122+
again on to the consumer service.
124123

125124
__ loginTemplate_
126125

@@ -141,7 +140,7 @@ Refresh the token
141140
+++++++++++++++++
142141
The page showing the access token retrieved from the :term:`Authorization Server` also let you make a POST request to
143142
the server itself to swap the refresh token for another, brand new access token.
144-
Just fill in the missing form fields and click the Refresh button: if everything goes smooth you will se the access and
143+
Just fill in the missing form fields and click the Refresh button: if everything goes smooth you will see the access and
145144
refresh token change their values, otherwise you will likely see an error message.
146145
When finished playing with your authorization server, take note of both the access and refresh tokens, we will use them
147146
for the next part of the tutorial.

0 commit comments

Comments
 (0)