@@ -22,7 +22,9 @@ class ApplicationRegistration(LoginRequiredMixin, CreateView):
2222 View used to register a new Application for the request.user
2323 """
2424
25+ context_object_name = "application"
2526 template_name = "oauth2_provider/application_registration_form.html"
27+ success_template_name = "oauth2_provider/application_detail.html"
2628
2729 def get_form_class (self ):
2830 """
@@ -32,8 +34,6 @@ def get_form_class(self):
3234 get_application_model (),
3335 fields = (
3436 "name" ,
35- "client_id" ,
36- "client_secret" ,
3737 "hash_client_secret" ,
3838 "client_type" ,
3939 "authorization_grant_type" ,
@@ -46,7 +46,22 @@ def get_form_class(self):
4646
4747 def form_valid (self , form ):
4848 form .instance .user = self .request .user
49- return super ().form_valid (form )
49+ if not form .cleaned_data ["hash_client_secret" ]:
50+ return super ().form_valid (form )
51+
52+ client_secret = form .instance .client_secret
53+ self .object = form .save ()
54+ return self .response_class (
55+ request = self .request ,
56+ template = self .success_template_name ,
57+ context = self .get_context_data (
58+ client_secret = client_secret ,
59+ show_client_secret_once = self .object .hash_client_secret ,
60+ ** {self .context_object_name : self .object },
61+ ),
62+ using = self .template_engine ,
63+ content_type = self .content_type ,
64+ )
5065
5166
5267class ApplicationDetail (ApplicationOwnerIsUserMixin , DetailView ):
@@ -57,6 +72,12 @@ class ApplicationDetail(ApplicationOwnerIsUserMixin, DetailView):
5772 context_object_name = "application"
5873 template_name = "oauth2_provider/application_detail.html"
5974
75+ def get_context_data (self , ** kwargs ):
76+ ctx = super ().get_context_data (** kwargs )
77+ if not ctx ["application" ].hash_client_secret :
78+ ctx ["client_secret" ] = ctx ["application" ].client_secret
79+ return ctx
80+
6081
6182class ApplicationList (ApplicationOwnerIsUserMixin , ListView ):
6283 """
0 commit comments