33Authenticating via OAuth
44========================
55
6- PRAW supports the three types of applications that can be registered on
6+ PRAW supports all three types of applications that can be registered on
77Reddit. Those are:
88
99* `Web Applications <https://github.com/reddit-archive/reddit/wiki/OAuth2-App-Types#web-app >`_
@@ -14,10 +14,10 @@ Before you can use any one of these with PRAW, you must first `register
1414<https://www.reddit.com/prefs/apps/> `_ an application of the appropriate type
1515on Reddit.
1616
17- If your app does not require a user context, it is :ref: `read-only <read_only_application >`.
17+ If your application does not require a user context, it is :ref: `read-only <read_only_application >`.
1818
1919PRAW supports the flows that each of these applications can use. The
20- following table defines which tables can use which flows:
20+ following table defines which application types can use which flows:
2121
2222.. rst-class :: center_table_items
2323
@@ -131,12 +131,11 @@ When registering your application you must provide a valid redirect URI. If you
131131running a website you will want to enter the appropriate callback URL and configure that
132132endpoint to complete the code flow.
133133
134- If you aren't actually running a website, you can use the :ref: `refresh_token ` script to
135- obtain ``refresh_tokens ``. Enter ``http://localhost:8080 `` as the redirect URI when
136- using this script.
134+ If you aren't actually running a website, you can follow the :ref: `refresh_token `
135+ tutorial to learn how to obtain and use the initial refresh token.
137136
138- Whether or not you use the script there are two processes involved in obtaining
139- access or refresh tokens.
137+ Whether or not you follow the :ref: ` refresh_token ` tutorial there are two processes
138+ involved in obtaining access or refresh tokens.
140139
141140.. _auth_url :
142141
@@ -155,24 +154,26 @@ URL. You can do that as follows:
155154 )
156155 print (reddit.auth.url([" identity" ], " ..." , " permanent" ))
157156
158- The above will output an authorization URL for a permanent token that has only the
159- `identity ` scope. See :meth: `.url ` for more information on these parameters.
157+ The above will output an authorization URL for a permanent token (i.e., the resulting
158+ authorization will include both a short-lived ``access_token ``, and a longer-lived, single
159+ use ``refresh_token ``) that has only the ``identity `` scope. See :meth: `.url ` for more
160+ information on these parameters.
160161
161162This URL should be accessed by the account that desires to authorize their Reddit access
162163to your application. On completion of that flow, the user's browser will be redirected
163- to the specified ``redirect_uri ``. After extracting verifying the ``state `` and
164- extracting the ``code `` you can obtain the refresh token via:
164+ to the specified ``redirect_uri ``. After verifying the ``state `` and extracting the
165+ ``code `` you can obtain the refresh token via:
165166
166167.. code-block :: python
167168
168169 print (reddit.auth.authorize(code))
169170 print (reddit.user.me())
170171
171172 The first line of output is the ``refresh_token ``. You can save this for later use (see
172- :ref: `using_refresh_token `).
173+ :ref: `using_refresh_tokens `).
173174
174175The second line of output reveals the name of the Redditor that completed the code flow.
175- It also indicates that the `` reddit ` ` instance is now associated with that account.
176+ It also indicates that the :class: ` .Reddit ` instance is now associated with that account.
176177
177178The code flow can be used with an **installed ** application just as described above with
178179one change: set the value of ``client_secret `` to ``None `` when initializing
@@ -256,28 +257,3 @@ such as in installed applications where the end user could retrieve the ``client
256257 from each other (as the supplied device id *should * be a unique string per both
257258 device (in the case of a web app, server) and user (in the case of a web app,
258259 browser session).
259-
260- .. _using_refresh_token :
261-
262- Using a Saved Refresh Token
263- ---------------------------
264-
265- A saved refresh token can be used to immediately obtain an authorized instance of
266- :class: `.Reddit ` like so:
267-
268- .. code-block :: python
269-
270- reddit = praw.Reddit(client_id = " SI8pN3DSbt0zor" ,
271- client_secret = " xaxkj7HNh8kwg8e5t4m6KvSrbTI" ,
272- refresh_token = " WeheY7PwgeCZj4S3QgUcLhKE5S2s4eAYdxM" ,
273- user_agent = " testscript by u/fakebot3"
274- )
275- print (reddit.auth.scopes())
276-
277- The output from the above code displays which scopes are available on the
278- :class: `.Reddit ` instance.
279-
280- .. note ::
281-
282- Observe that ``redirect_uri `` does not need to be provided in such cases. It is only
283- needed when :meth: `.url ` is used.
0 commit comments