Skip to content

Commit 481a97d

Browse files
committed
Add device authorization doc
1 parent 3bf3dcc commit 481a97d

File tree

8 files changed

+63
-3
lines changed

8 files changed

+63
-3
lines changed

docs/oauth2/endpoints/device.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
=============
2+
Device
3+
=============
4+
5+
The device endpoint is used to initiate the authorization flow by requesting a set of
6+
verification codes from the authorization server by making an HTTP "POST" request to
7+
the device authorization endpoint.
8+
9+
** Device Authorization Request **
10+
The client makes a device authorization request to the device
11+
authorization endpoint by including the following parameters using
12+
the "application/x-www-form-urlencoded" format:
13+
14+
POST /device_authorization HTTP/1.1
15+
Host: server.example.com
16+
Content-Type: application/x-www-form-urlencoded
17+
client_id=123456&scope=example_scope
18+
19+
.. code-block:: python
20+
21+
# Initial setup
22+
from your_validator import your_validator
23+
verification_uri = "https://example.com/device"
24+
25+
def user_code():
26+
# some logic to generate a random string...
27+
return "123-456"
28+
29+
# user code is optional
30+
server = DeviceApplicationServer(your_validator, verification_uri, user_code)
31+
32+
headers, data, status = server.create_device_authorization_response(request)
33+
34+
# response from /device_authorization endpoint on your server
35+
from your_framework import http_response
36+
http_response(data, status=status, headers=headers)
37+
38+
39+
40+
.. code-block:: python
41+
42+
# example response
43+
{
44+
"device_code": "GmRhmhcxhwAzkoEqiMEg_DnyEysNkuNhszIySk9eS",
45+
"user_code": "123-456",
46+
"verification_uri": "https://example.com/device",
47+
"verification_uri_complete":
48+
"https://example.com/device?user_code=WDJB-MJHT",
49+
"expires_in": 1800,
50+
"interval": 5
51+
}
52+
53+
54+
.. autoclass:: oauthlib.oauth2.DeviceAuthorizationEndpoint
55+
:members:

docs/oauth2/endpoints/endpoints.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ client attempts to access the user resources on their behalf.
1515
:maxdepth: 2
1616

1717
authorization
18+
device
1819
introspect
1920
token
2021
metadata

docs/oauth2/preconfigured_servers.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@ This function is passed the request object and a boolean indicating whether to g
3636

3737
.. autoclass:: oauthlib.oauth2.BackendApplicationServer
3838
:members:
39+
40+
41+
.. autoclass:: oauthlib.oauth2.DeviceApplicationServer
42+
:members:

oauthlib/oauth2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
from .rfc6749.tokens import BearerToken, OAuth2Token
3535
from .rfc6749.utils import is_secure_transport
3636
from .rfc8628.clients import DeviceClient
37-
from .rfc8628.endpoints import DeviceAuthorizationEndpoint
37+
from .rfc8628.endpoints import DeviceAuthorizationEndpoint, DeviceApplicationServer

oauthlib/oauth2/rfc8628/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@
77
"""
88

99
import logging
10-
from .pre_configured import DeviceApplicationServer
1110

1211
log = logging.getLogger(__name__)

oauthlib/oauth2/rfc8628/endpoints/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
for consuming and providing OAuth 2.0 Device Authorization RFC8628.
77
"""
88
from .device_authorization import DeviceAuthorizationEndpoint
9+
from .pre_configured import DeviceApplicationServer

tests/oauth2/rfc8628/endpoints/test_error_responses.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from oauthlib.common import Request, urlencode
55
from oauthlib.oauth2.rfc6749 import errors
6-
from oauthlib.oauth2.rfc8628.pre_configured import DeviceApplicationServer
6+
from oauthlib.oauth2.rfc8628.endpoints.pre_configured import DeviceApplicationServer
77
from oauthlib.oauth2.rfc8628.request_validator import RequestValidator
88

99

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy