Bump django-oauth-toolkit to 2.2.* (#2985)

This commit is contained in:
Raphael Michel
2022-12-19 12:26:45 +01:00
committed by GitHub
parent 60554dad9a
commit 15272cc3e6
6 changed files with 145 additions and 29 deletions

View File

@@ -65,6 +65,10 @@ class OAuthApplicationRegistrationView(ApplicationRegistration):
def form_valid(self, form):
form.instance.client_type = 'confidential'
form.instance.authorization_grant_type = 'authorization-code'
secret = generate_client_secret()
messages.success(self.request, _('Your application has been created and an application secret has been generated. '
'Please copy and save it right now as it will not be shown again: {secret}').format(secret=secret))
form.instance.client_secret = secret
oauth_application_registered.send(
sender=self.request, user=self.request.user, application=form.instance
)
@@ -74,18 +78,14 @@ class OAuthApplicationRegistrationView(ApplicationRegistration):
class ApplicationUpdateForm(forms.ModelForm):
class Meta:
model = OAuthApplication
fields = ("name", "client_id", "client_secret", "redirect_uris")
fields = ("name", "client_id", "redirect_uris")
def clean_client_id(self):
return self.instance.client_id
def clean_client_secret(self):
return self.instance.client_secret
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['client_id'].widget.attrs['readonly'] = True
self.fields['client_secret'].widget.attrs['readonly'] = True
class OAuthApplicationUpdateView(ApplicationUpdate):
@@ -103,8 +103,10 @@ class OAuthApplicationRollView(ApplicationDetail):
def post(self, request, *args, **kwargs):
self.object = self.get_object()
messages.success(request, _('A new client secret has been generated and is now effective.'))
self.object.client_secret = generate_client_secret()
secret = generate_client_secret()
messages.success(request, _('A new client secret has been generated. Please copy and save it right now as '
'it will not be shown again: {secret}').format(secret=secret))
self.object.client_secret = secret
self.object.save()
return HttpResponseRedirect(self.object.get_absolute_url())