Skip to content

Add dynamic help text for client_secret field on application form#1697

Open
emmanuelangelo4199 wants to merge 3 commits into
django-oauth:masterfrom
emmanuelangelo4199:feature/1635-client-secret-help-text
Open

Add dynamic help text for client_secret field on application form#1697
emmanuelangelo4199 wants to merge 3 commits into
django-oauth:masterfrom
emmanuelangelo4199:feature/1635-client-secret-help-text

Conversation

@emmanuelangelo4199

@emmanuelangelo4199 emmanuelangelo4199 commented May 21, 2026

Copy link
Copy Markdown

Fixes #1635 - warns users to save their secret on creation, and informs them it is hashed and unrecoverable when editing.

Fixes #

Description of the Change

Checklist

  • PR only contains one change (considered splitting up PR)
  • unit-test added
  • documentation updated
  • CHANGELOG.md updated (only for user relevant changes)
  • author name in AUTHORS
  • tests/app/idp updated to demonstrate new features
  • tests/app/rp updated to demonstrate new features

Fixes django-oauth#1635 - warns users to save their secret on creation,
and informs them it is hashed and unrecoverable when editing.
@dopry dopry force-pushed the feature/1635-client-secret-help-text branch from 4dca86a to dec5e2f Compare May 29, 2026 19:50
@dopry dopry requested a review from Copilot May 29, 2026 19:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR aims to improve the UX of registering/editing OAuth applications by providing context-sensitive help text for the client_secret field: a “copy it now” warning on creation, and a “hashed/unrecoverable” note on edit.

Changes:

  • Introduces an ApplicationForm that sets client_secret help text based on whether the instance already exists.
  • Updates application create/update views to use that form via modelform_factory.
  • Adds tests asserting the help text differs between the registration and update forms.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
oauth2_provider/forms.py Adds ApplicationForm to set dynamic help text for client_secret.
oauth2_provider/views/application.py Switches application create/update views to use ApplicationForm and centralizes the field list.
tests/test_application_views.py Adds assertions for dynamic help text behavior in register vs update views.

Comment thread oauth2_provider/forms.py
Comment on lines 1 to 6
from django import forms
from django.forms.models import modelform_factory
from .models import get_application_model


class AllowForm(forms.Form):
Comment thread oauth2_provider/forms.py
Comment on lines +33 to +45
class ApplicationForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.instance and self.instance.pk:
self.fields["client_secret"].help_text = (
"⚠️ The client secret has been hashed and can no longer be viewed. "
"If you need the original value, you must regenerate it and save it immediately."
)
else:
self.fields["client_secret"].help_text = (
"⚠️ Copy and store this secret now. "
"Once saved, it will be hashed and cannot be recovered."
) No newline at end of file
Comment thread oauth2_provider/forms.py
Comment on lines +36 to +44
if self.instance and self.instance.pk:
self.fields["client_secret"].help_text = (
"⚠️ The client secret has been hashed and can no longer be viewed. "
"If you need the original value, you must regenerate it and save it immediately."
)
else:
self.fields["client_secret"].help_text = (
"⚠️ Copy and store this secret now. "
"Once saved, it will be hashed and cannot be recovered."
Comment thread tests/test_application_views.py
@dopry dopry added this to the 3.4.0 milestone May 30, 2026
emmanuelangelo4199 and others added 2 commits June 2, 2026 01:57
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add dynamic help text for the client_secret field on the application form

3 participants