@@ -22,7 +22,9 @@ class ApplicationRegistration(LoginRequiredMixin, CreateView):
22
22
View used to register a new Application for the request.user
23
23
"""
24
24
25
+ context_object_name = "application"
25
26
template_name = "oauth2_provider/application_registration_form.html"
27
+ success_template_name = "oauth2_provider/application_detail.html"
26
28
27
29
def get_form_class (self ):
28
30
"""
@@ -32,8 +34,6 @@ def get_form_class(self):
32
34
get_application_model (),
33
35
fields = (
34
36
"name" ,
35
- "client_id" ,
36
- "client_secret" ,
37
37
"hash_client_secret" ,
38
38
"client_type" ,
39
39
"authorization_grant_type" ,
@@ -46,7 +46,22 @@ def get_form_class(self):
46
46
47
47
def form_valid (self , form ):
48
48
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
+ )
50
65
51
66
52
67
class ApplicationDetail (ApplicationOwnerIsUserMixin , DetailView ):
@@ -57,6 +72,12 @@ class ApplicationDetail(ApplicationOwnerIsUserMixin, DetailView):
57
72
context_object_name = "application"
58
73
template_name = "oauth2_provider/application_detail.html"
59
74
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
+
60
81
61
82
class ApplicationList (ApplicationOwnerIsUserMixin , ListView ):
62
83
"""
0 commit comments