Skip to content

Commit 1b96825

Browse files
committed
Use a template to render the flash message containing client_secret
1 parent f65b59a commit 1b96825

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{% load i18n %}
2+
3+
{% block message_content %}
4+
{% blocktranslate %}
5+
The application client secret is:
6+
<div style="font-family: monospace; overflow-wrap: break-word; width: 100%;">{{ client_secret }}</div>
7+
This will only be shown once, so copy it now!
8+
{% endblocktranslate %}
9+
{% endblock %}

oauth2_provider/views/application.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from django.contrib import messages
22
from django.contrib.auth.mixins import LoginRequiredMixin
33
from django.forms.models import modelform_factory
4+
from django.template.loader import render_to_string
45
from django.urls import reverse_lazy
5-
from django.utils.safestring import mark_safe
6-
from django.utils.translation import gettext as _
76
from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView
87

98
from ..models import get_application_model
@@ -53,14 +52,9 @@ def form_valid(self, form):
5352
messages.add_message(
5453
self.request,
5554
messages.SUCCESS,
56-
# Since the client_secret is not user-supplied, we can manually mark this entire
57-
# string as safe so Django doesn't re-encode the HTML markup
58-
mark_safe(
59-
_(
60-
"The application client secret is:<br /><code>%s</code><br />"
61-
"This will only be shown once, so copy it now!"
62-
)
63-
% form.instance.client_secret
55+
render_to_string(
56+
"oauth2_provider/application_client_secret_message.html",
57+
{"client_secret": form.instance.client_secret},
6458
),
6559
)
6660
return super().form_valid(form)

0 commit comments

Comments
 (0)