Skip to content

Commit b7273a7

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

File tree

19 files changed

+460
-64
lines changed

19 files changed

+460
-64
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: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,9 @@ 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
20-
RUN apt-get install -y --no-install-recommends gcc libc-dev python3-dev git openssh-client libpq-dev file libev-dev
14+
RUN apt-get install -y --no-install-recommends gcc libc-dev python3-dev git openssh-client libpq-dev file libev-dev gettext
2115
# bundle code in a virtual env to make copying to the final image without all the upstream stuff easier.
2216
RUN python -m venv /opt/venv
2317
ENV PATH="/opt/venv/bin:$PATH"
@@ -28,7 +22,8 @@ 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 cd /code/oauth2_provider && django-admin compilemessages
26+
RUN STATIC_ROOT="static" python manage.py collectstatic --noinput
3227

3328

3429

@@ -47,8 +42,8 @@ ENV SENTRY_RELEASE=${GIT_SHA1}
4742
# disable debug mode, but allow all hosts by default when running in docker
4843
ENV DEBUG=False
4944
ENV ALLOWED_HOSTS="*"
50-
ENV TEMPLATES_DIRS="/data/templates"
51-
ENV STATIC_ROOT="/data/static"
45+
ENV TEMPLATES_DIRS="/code/tests/app/idp/templates"
46+
ENV STATIC_ROOT="/code/tests/app/idp/static"
5247
ENV DATABASE_URL="sqlite:////data/db.sqlite3"
5348

5449

@@ -57,9 +52,6 @@ ENV DATABASE_URL="sqlite:////data/db.sqlite3"
5752
COPY --from=builder /opt/venv /opt/venv
5853
ENV PATH="/opt/venv/bin:$PATH"
5954
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
6355

6456
WORKDIR /code/tests/app/idp
6557
RUN apt-get update && apt-get install -y \

docs/contributing.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,18 +380,18 @@ Development with astral uv package and project manager.
380380
We have experimental support for `astral uv <https://docs.astral.sh/uv/>`__. It provides an improved
381381
developer experience over vanilla virtualenv/venv and pip by managing multiple python versions,
382382
virtual environments and dependencies in a more efficient way. The ``uv run`` command automatically
383-
syncs dependencies and python version before running the command, saving multiple steps when
383+
syncs dependencies and python version before running the command, saving multiple steps when
384384
working on multiple branches with different dependencies.
385385

386386
You can use uv sync to set up your environment and install dependencies and run python::
387387

388-
... code-block:: bash
388+
.. code-block:: bash
389389
uv sync # checks deps, installs virtualenv and dependencies as necessary
390390
uv run ... # runs command in the uv environment, syncs deps and python version first if necessary
391391
392392
To run tox uv use `tox uv <https://github.com/tox-dev/tox-uv>`__::
393393

394-
... code-block:: bash
394+
.. code-block:: bash
395395
uv tool install tox --with tox-uv # use uv to install
396396
tox --version # validate you are using the installed tox
397397
tox r -e py312 # will use uv

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):

0 commit comments

Comments
 (0)