Skip to content

Commit 13538a6

Browse files
marcus-sonestedtpre-commit-ci[bot]n2ygk
authored
Doc: Replace heroku service with postman in tutorial part 1 (#1251)
* Replace heroku with postman tutorial * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update tutorial_01.rst * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update AUTHORS * Update docs/tutorial/tutorial_01.rst Co-authored-by: Alan Crosswell <[email protected]> * Update tutorial_01.rst --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com.> Co-authored-by: Alan Crosswell <[email protected]>
1 parent fc50ff1 commit 13538a6

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ Víðir Valberg Guðmundsson
9090
Will Beaufoy
9191
pySilver
9292
Łukasz Skarżyński
93+
Marcus Sonestedt

docs/tutorial/tutorial_01.rst

+26-14
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ point your browser to http://localhost:8000/o/applications/ and add an Applicati
8989
* `Redirect uris`: Applications must register at least one redirection endpoint before using the
9090
authorization endpoint. The :term:`Authorization Server` will deliver the access token to the client only if the client
9191
specifies one of the verified redirection uris. For this tutorial, paste verbatim the value
92-
`http://django-oauth-toolkit.herokuapp.com/consumer/exchange/`
92+
`https://www.getpostman.com/oauth2/callback`
9393

9494
* `Client type`: this value affects the security level at which some communications between the client application and
9595
the authorization server are performed. For this tutorial choose *Confidential*.
@@ -105,17 +105,28 @@ process we'll explain shortly)
105105
Test Your Authorization Server
106106
------------------------------
107107
Your authorization server is ready and can begin issuing access tokens. To test the process you need an OAuth2
108-
consumer; if you are familiar enough with OAuth2, you can use curl, requests, or anything that speaks http. For the rest
109-
of us, there is a `consumer service <http://django-oauth-toolkit.herokuapp.com/consumer/>`_ deployed on Heroku to test
110-
your provider.
108+
consumer; if you are familiar enough with OAuth2, you can use curl, requests, or anything that speaks http.
109+
110+
For this tutorial, we suggest using [Postman](https://www.postman.com/downloads/) :
111+
112+
Open up the Authorization tab under a request and, for this tutorial, set the fields as follows:
113+
114+
* Grant type: `Authorization code (With PKCE)`
115+
* Callback URL: `https://www.getpostman.com/oauth2/callback` <- need to be in your added application
116+
* Authorize using browser: leave unchecked
117+
* Auth URL: `http://localhost:8000/o/authorize/`
118+
* Access Token URL: `http://localhost:8000/o/token/`
119+
* Client ID: `random string for this app, as generated`
120+
* Client Secret: `random string for this app, as generated` <- must be before hashing, should not begin with 'pbkdf2_sha256' or similar
121+
122+
The rest can be left to their (mostly empty) default values.
111123

112124
Build an Authorization Link for Your Users
113125
++++++++++++++++++++++++++++++++++++++++++
114126
Authorizing an application to access OAuth2 protected data in an :term:`Authorization Code` flow is always initiated
115-
by the user. Your application can prompt users to click a special link to start the process. Go to the
116-
`Consumer <http://django-oauth-toolkit.herokuapp.com/consumer/>`_ page and complete the form by filling in your
117-
application's details obtained from the steps in this tutorial. Submit the form, and you'll receive a link your users can
118-
use to access the authorization page.
127+
by the user. Your application can prompt users to click a special link to start the process.
128+
129+
Here, we click "Get New Access Token" in postman, which should open your browser and show django's login.
119130

120131
Authorize the Application
121132
+++++++++++++++++++++++++
@@ -125,18 +136,19 @@ page is login protected by django-oauth-toolkit. Login, then you should see the
125136
her authorization to the client application. Flag the *Allow* checkbox and click *Authorize*, you will be redirected
126137
again to the consumer service.
127138

128-
__ loginTemplate_
139+
Possible errors:
129140

130-
If you are not redirected to the correct page after logging in successfully,
131-
you probably need to `setup your login template correctly`__.
141+
* loginTemplate: If you are not redirected to the correct page after logging in successfully, you probably need to `setup your login template correctly`__.
142+
* invalid client: client id and client secret needs to be correct. Secret cannot be copied from Django admin after creation.
143+
(but you can reset it by pasting the same random string into Django admin and into Postman, to avoid recreating the app)
144+
* invalid callback url: Add the postman link into your app in Django admin.
145+
* invalid_request: Use "Authorization Code (With PCKE)" from postman or disable PKCE in Django
132146

133147
Exchange the token
134148
++++++++++++++++++
135149
At this point your authorization server redirected the user to a special page on the consumer passing in an
136150
:term:`Authorization Code`, a special token the consumer will use to obtain the final access token.
137-
This operation is usually done automatically by the client application during the request/response cycle, but we cannot
138-
make a POST request from Heroku to your localhost, so we proceed manually with this step. Fill the form with the
139-
missing data and click *Submit*.
151+
140152
If everything is ok, you will be routed to another page showing your access token, the token type, its lifetime and
141153
the :term:`Refresh Token`.
142154

0 commit comments

Comments
 (0)