Skip to content

Commit

Permalink
Use a template to render the flash message containing client_secret
Browse files Browse the repository at this point in the history
  • Loading branch information
blag committed Sep 22, 2024
1 parent ca5428d commit 2881416
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% load i18n %}

{% block message_content %}
{% blocktranslate %}
The application client secret is:
<div style="font-family: monospace; overflow-wrap: break-word; width: 100%;">{{ client_secret }}</div>
This will only be shown once, so copy it now!
{% endblocktranslate %}
{% endblock %}
14 changes: 4 additions & 10 deletions oauth2_provider/views/application.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.forms.models import modelform_factory
from django.template.loader import render_to_string
from django.urls import reverse_lazy
from django.utils.safestring import mark_safe
from django.utils.translation import gettext as _
from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView

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

0 comments on commit 2881416

Please sign in to comment.