Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/tutorial/tutorial_06.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ but generally, it is assumed the device is unable to safely store the client sec

Ensure the setting ``OAUTH_DEVICE_VERIFICATION_URI`` is set to a URI you want to return in the
`verification_uri` key in the response. This is what the device will display to the user.
Optionally, configure ``OAUTH_DEVICE_VERIFICATION_URI_COMPLETE`` to something like
``http://127.0.0.1:8000/o/device?user_code={user_code}``.
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider clarifying that the substituted {user_code} should be URL-encoded when constructing the complete URI (especially if deployments customize the user_code format), since this example places it in a query string.

Suggested change
``http://127.0.0.1:8000/o/device?user_code={user_code}``.
``http://127.0.0.1:8000/o/device?user_code={user_code}``, where ``{user_code}`` is URL-encoded before substitution.

Copilot uses AI. Check for mistakes.

1. Navigate to the tests/app/idp directory:

Expand Down
3 changes: 3 additions & 0 deletions oauth2_provider/views/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def get_success_url(self):
},
)

def get_initial(self):
return {"user_code": self.request.GET.get("user_code", "")}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_initial() fully replaces the base implementation and may drop any initial values provided by self.initial or parent classes/mixins. Safer is to start from super().get_initial() and then set/override user_code.

Suggested change
return {"user_code": self.request.GET.get("user_code", "")}
initial = super().get_initial()
initial["user_code"] = self.request.GET.get("user_code", "")
return initial

Copilot uses AI. Check for mistakes.
Comment on lines +102 to +103
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces new behavior (query-string-driven prefill) that should be covered by a unit test to prevent regressions (e.g., request with ?user_code=ABCD-EFGH pre-fills the form; request without the param preserves default initial behavior).

Copilot uses AI. Check for mistakes.

def form_valid(self, form):
"""
Sets the device_grant on the instance so that it can be accessed
Expand Down
Loading