Skip to content

Commit 18047ab

Browse files
author
Michael Li
committed
chore: dynamic help_text for client_secret (#1628)
1 parent bade920 commit 18047ab

File tree

14 files changed

+425
-50
lines changed

14 files changed

+425
-50
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Jun Zhou
8585
Kaleb Porter
8686
Kristian Rune Larsen
8787
Lazaros Toumanidis
88+
lrq315
8889
Ludwig Hähne
8990
Łukasz Skarżyński
9091
Madison Swain-Bowden

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
### Fixed
2121
* #1252 Fix crash when 'client' is in token request body
2222
* #1496 Fix error when Bearer token string is empty but preceded by `Bearer` keyword.
23+
* #1628 Fix inaccurate help_text on client_secret field of Application model
2324
<!--
2425
### Security
2526
-->

Dockerfile

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ FROM python:3.11.6-slim as builder
99
ENV PYTHONDONTWRITEBYTECODE 1
1010
ENV PYTHONUNBUFFERED 1
1111

12-
ENV DEBUG=False
13-
ENV ALLOWED_HOSTS="*"
14-
ENV TEMPLATES_DIRS="/data/templates"
15-
ENV STATIC_ROOT="/data/static"
16-
ENV DATABASE_URL="sqlite:////data/db.sqlite3"
17-
1812
RUN apt-get update
1913
# Build Deps
2014
RUN apt-get install -y --no-install-recommends gcc libc-dev python3-dev git openssh-client libpq-dev file libev-dev
@@ -28,7 +22,7 @@ COPY . /code
2822
WORKDIR /code/tests/app/idp
2923
RUN pip install -r requirements.txt
3024
RUN pip install gunicorn
31-
RUN python manage.py collectstatic --noinput
25+
RUN STATIC_ROOT="static" python manage.py collectstatic --noinput
3226

3327

3428

@@ -47,8 +41,8 @@ ENV SENTRY_RELEASE=${GIT_SHA1}
4741
# disable debug mode, but allow all hosts by default when running in docker
4842
ENV DEBUG=False
4943
ENV ALLOWED_HOSTS="*"
50-
ENV TEMPLATES_DIRS="/data/templates"
51-
ENV STATIC_ROOT="/data/static"
44+
ENV TEMPLATES_DIRS="/code/tests/app/idp/templates"
45+
ENV STATIC_ROOT="/code/tests/app/idp/static"
5246
ENV DATABASE_URL="sqlite:////data/db.sqlite3"
5347

5448

@@ -57,9 +51,6 @@ ENV DATABASE_URL="sqlite:////data/db.sqlite3"
5751
COPY --from=builder /opt/venv /opt/venv
5852
ENV PATH="/opt/venv/bin:$PATH"
5953
COPY --from=builder /code /code
60-
RUN mkdir -p /data/static /data/templates
61-
COPY --from=builder /code/tests/app/idp/static /data/static
62-
COPY --from=builder /code/tests/app/idp/templates /data/templates
6354

6455
WORKDIR /code/tests/app/idp
6556
RUN apt-get update && apt-get install -y \

oauth2_provider/admin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.contrib import admin
22
from django.contrib.auth import get_user_model
33

4+
from oauth2_provider.forms import ApplicationForm
45
from oauth2_provider.models import (
56
get_access_token_admin_class,
67
get_access_token_model,
@@ -19,6 +20,7 @@
1920

2021

2122
class ApplicationAdmin(admin.ModelAdmin):
23+
form = ApplicationForm
2224
list_display = ("pk", "name", "user", "client_type", "authorization_grant_type")
2325
list_filter = ("client_type", "authorization_grant_type", "skip_authorization")
2426
radio_fields = {
@@ -28,6 +30,9 @@ class ApplicationAdmin(admin.ModelAdmin):
2830
search_fields = ("name",) + (("user__email",) if has_email else ())
2931
raw_id_fields = ("user",)
3032

33+
class Media:
34+
js = ("oauth2_provider/admin/application_form.js",)
35+
3136

3237
class AccessTokenAdmin(admin.ModelAdmin):
3338
list_display = ("token", "user", "application", "expires")

oauth2_provider/forms.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,48 @@
11
from django import forms
2+
from django.utils.encoding import force_str
3+
from django.utils.translation import gettext_lazy as _
4+
5+
from .models import get_application_model
6+
7+
8+
HASHED_WARNING_TEXT = _("Hashed on save. Copy it now if this is a new secret.")
9+
10+
11+
def get_application_form_class():
12+
application_model = get_application_model()
13+
14+
class ApplicationForm(forms.ModelForm):
15+
"""
16+
Form for Application model with dynamic help_text for client_secret field
17+
based on hash_client_secret value.
18+
"""
19+
20+
class Meta:
21+
model = application_model
22+
fields = (
23+
"name",
24+
"client_id",
25+
"client_secret",
26+
"hash_client_secret",
27+
"client_type",
28+
"authorization_grant_type",
29+
"redirect_uris",
30+
"post_logout_redirect_uris",
31+
"allowed_origins",
32+
"algorithm",
33+
)
34+
35+
def __init__(self, *args, **kwargs):
36+
super().__init__(*args, **kwargs)
37+
38+
self.fields.get("client_secret").widget.attrs.setdefault(
39+
"data-hashed-warning", force_str(HASHED_WARNING_TEXT)
40+
)
41+
42+
return ApplicationForm
43+
44+
45+
ApplicationForm = get_application_form_class()
246

347

448
class AllowForm(forms.Form):
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: PACKAGE VERSION\n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"POT-Creation-Date: 2025-12-15 01:04+0800\n"
12+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14+
"Language-Team: LANGUAGE <[email protected]>\n"
15+
"Language: \n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=UTF-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Plural-Forms: nplurals=1; plural=0;\n"
20+
#: oauth2_provider/forms.py:6
21+
msgid "Hashed on save. Copy it now if this is a new secret."
22+
msgstr "保存时会进行哈希处理。如果这是一个新的密钥,请立即复制并保存。"
23+
24+
#: oauth2_provider/models.py:87
25+
msgid "Confidential"
26+
msgstr ""
27+
28+
#: oauth2_provider/models.py:88
29+
msgid "Public"
30+
msgstr ""
31+
32+
#: oauth2_provider/models.py:98
33+
msgid "Authorization code"
34+
msgstr ""
35+
36+
#: oauth2_provider/models.py:99
37+
msgid "Device Code"
38+
msgstr ""
39+
40+
#: oauth2_provider/models.py:100
41+
msgid "Implicit"
42+
msgstr ""
43+
44+
#: oauth2_provider/models.py:101
45+
msgid "Resource owner password-based"
46+
msgstr ""
47+
48+
#: oauth2_provider/models.py:102
49+
msgid "Client credentials"
50+
msgstr ""
51+
52+
#: oauth2_provider/models.py:103
53+
msgid "OpenID connect hybrid"
54+
msgstr ""
55+
56+
#: oauth2_provider/models.py:110
57+
msgid "No OIDC support"
58+
msgstr ""
59+
60+
#: oauth2_provider/models.py:111
61+
msgid "RSA with SHA-2 256"
62+
msgstr ""
63+
64+
#: oauth2_provider/models.py:112
65+
msgid "HMAC with SHA-2 256"
66+
msgstr ""
67+
68+
#: oauth2_provider/models.py:127
69+
msgid "Allowed URIs list, space separated"
70+
msgstr ""
71+
72+
#: oauth2_provider/models.py:131
73+
msgid "Allowed Post Logout URIs list, space separated"
74+
msgstr ""
75+
76+
#: oauth2_provider/models.py:141
77+
msgid "Client secret for authentication"
78+
msgstr ""
79+
80+
#: oauth2_provider/models.py:152
81+
msgid "Allowed origins list to enable CORS, space separated"
82+
msgstr ""
83+
84+
#: oauth2_provider/models.py:232
85+
#, python-brace-format
86+
msgid "redirect_uris cannot be empty with grant_type {grant_type}"
87+
msgstr ""
88+
89+
#: oauth2_provider/models.py:249
90+
msgid "You must set OIDC_RSA_PRIVATE_KEY to use RSA algorithm"
91+
msgstr ""
92+
93+
#: oauth2_provider/models.py:258
94+
msgid "You cannot use HS256 with public grants or clients"
95+
msgstr ""
96+
97+
#: oauth2_provider/models.py:674
98+
msgid "Authorized"
99+
msgstr ""
100+
101+
#: oauth2_provider/models.py:675
102+
msgid "Authorization pending"
103+
msgstr ""
104+
105+
#: oauth2_provider/models.py:676
106+
msgid "Expired"
107+
msgstr ""
108+
109+
#: oauth2_provider/models.py:677
110+
msgid "Denied"
111+
msgstr ""
112+
113+
#: oauth2_provider/oauth2_validators.py:249
114+
msgid "The access token is invalid."
115+
msgstr ""
116+
117+
#: oauth2_provider/oauth2_validators.py:256
118+
msgid "The access token has expired."
119+
msgstr ""
120+
121+
#: oauth2_provider/oauth2_validators.py:263
122+
msgid "The access token is valid but does not have enough scope."
123+
msgstr ""
124+
125+
#: oauth2_provider/templates/oauth2_provider/application_confirm_delete.html:6
126+
msgid "Are you sure to delete the application"
127+
msgstr ""
128+
129+
#: oauth2_provider/templates/oauth2_provider/application_confirm_delete.html:12
130+
#: oauth2_provider/templates/oauth2_provider/authorize.html:29
131+
msgid "Cancel"
132+
msgstr ""
133+
134+
#: oauth2_provider/templates/oauth2_provider/application_confirm_delete.html:13
135+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:53
136+
#: oauth2_provider/templates/oauth2_provider/authorized-token-delete.html:7
137+
msgid "Delete"
138+
msgstr ""
139+
140+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:10
141+
msgid "Client id"
142+
msgstr ""
143+
144+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:15
145+
msgid "Client secret"
146+
msgstr ""
147+
148+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:20
149+
msgid "Hash client secret"
150+
msgstr ""
151+
152+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:21
153+
msgid "yes,no"
154+
msgstr ""
155+
156+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:25
157+
msgid "Client type"
158+
msgstr ""
159+
160+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:30
161+
msgid "Authorization Grant Type"
162+
msgstr ""
163+
164+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:35
165+
msgid "Redirect Uris"
166+
msgstr ""
167+
168+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:40
169+
msgid "Post Logout Redirect Uris"
170+
msgstr ""
171+
172+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:45
173+
msgid "Allowed Origins"
174+
msgstr ""
175+
176+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:51
177+
#: oauth2_provider/templates/oauth2_provider/application_form.html:38
178+
msgid "Go Back"
179+
msgstr ""
180+
181+
#: oauth2_provider/templates/oauth2_provider/application_detail.html:52
182+
msgid "Edit"
183+
msgstr ""
184+
185+
#: oauth2_provider/templates/oauth2_provider/application_form.html:9
186+
msgid "Edit application"
187+
msgstr ""
188+
189+
#: oauth2_provider/templates/oauth2_provider/application_form.html:40
190+
msgid "Save"
191+
msgstr ""
192+
193+
#: oauth2_provider/templates/oauth2_provider/application_list.html:6
194+
msgid "Your applications"
195+
msgstr ""
196+
197+
#: oauth2_provider/templates/oauth2_provider/application_list.html:14
198+
msgid "New Application"
199+
msgstr ""
200+
201+
#: oauth2_provider/templates/oauth2_provider/application_list.html:17
202+
msgid "No applications defined"
203+
msgstr ""
204+
205+
#: oauth2_provider/templates/oauth2_provider/application_list.html:17
206+
msgid "Click here"
207+
msgstr ""
208+
209+
#: oauth2_provider/templates/oauth2_provider/application_list.html:17
210+
msgid "if you want to register a new one"
211+
msgstr ""
212+
213+
#: oauth2_provider/templates/oauth2_provider/application_registration_form.html:5
214+
msgid "Register a new application"
215+
msgstr ""
216+
217+
#: oauth2_provider/templates/oauth2_provider/authorize.html:8
218+
#: oauth2_provider/templates/oauth2_provider/authorize.html:30
219+
msgid "Authorize"
220+
msgstr ""
221+
222+
#: oauth2_provider/templates/oauth2_provider/authorize.html:17
223+
msgid "Application requires the following permissions"
224+
msgstr ""
225+
226+
#: oauth2_provider/templates/oauth2_provider/authorized-token-delete.html:6
227+
msgid "Are you sure you want to delete this token?"
228+
msgstr ""
229+
230+
#: oauth2_provider/templates/oauth2_provider/authorized-tokens.html:6
231+
msgid "Tokens"
232+
msgstr ""
233+
234+
#: oauth2_provider/templates/oauth2_provider/authorized-tokens.html:11
235+
msgid "revoke"
236+
msgstr ""
237+
238+
#: oauth2_provider/templates/oauth2_provider/authorized-tokens.html:19
239+
msgid "There are no authorized tokens yet."
240+
msgstr ""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Generated by Django 5.2.9 on 2025-12-14 17:02
2+
3+
import oauth2_provider.generators
4+
import oauth2_provider.models
5+
from django.db import migrations
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('oauth2_provider', '0013_alter_application_authorization_grant_type_device'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='application',
17+
name='client_secret',
18+
field=oauth2_provider.models.ClientSecretField(blank=True, db_index=True, default=oauth2_provider.generators.generate_client_secret, help_text='Client secret for authentication', max_length=255),
19+
),
20+
]

0 commit comments

Comments
 (0)