16
16
17
17
package org .mitre .oauth2 .web ;
18
18
19
+ import java .net .URI ;
20
+ import java .net .URISyntaxException ;
19
21
import java .util .Collection ;
20
22
import java .util .Date ;
21
23
import java .util .HashMap ;
26
28
27
29
import javax .servlet .http .HttpSession ;
28
30
31
+ import org .apache .http .client .utils .URIBuilder ;
29
32
import org .mitre .oauth2 .exception .DeviceCodeCreationException ;
30
33
import org .mitre .oauth2 .model .ClientDetailsEntity ;
31
34
import org .mitre .oauth2 .model .DeviceCode ;
@@ -134,11 +137,16 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
134
137
135
138
try {
136
139
DeviceCode dc = deviceCodeService .createNewDeviceCode (requestedScopes , client , parameters );
137
-
140
+
141
+ URI verificationUriComplete = new URIBuilder (config .getIssuer () + USER_URL )
142
+ .addParameter ("user_code" , dc .getUserCode ())
143
+ .build ();
144
+
138
145
Map <String , Object > response = new HashMap <>();
139
146
response .put ("device_code" , dc .getDeviceCode ());
140
147
response .put ("user_code" , dc .getUserCode ());
141
148
response .put ("verification_uri" , config .getIssuer () + USER_URL );
149
+ response .put ("verification_uri_complete" , verificationUriComplete );
142
150
if (client .getDeviceCodeValiditySeconds () != null ) {
143
151
response .put ("expires_in" , client .getDeviceCodeValiditySeconds ());
144
152
}
@@ -154,18 +162,31 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
154
162
model .put (JsonErrorView .ERROR_MESSAGE , dcce .getMessage ());
155
163
156
164
return JsonErrorView .VIEWNAME ;
165
+ } catch (URISyntaxException use ) {
166
+ logger .error ("unable to build verification_uri_complete due to wrong syntax of uri components" );
167
+ model .put (HttpCodeView .CODE , HttpStatus .INTERNAL_SERVER_ERROR );
168
+
169
+ return HttpCodeView .VIEWNAME ;
157
170
}
158
171
159
172
}
160
173
161
174
@ PreAuthorize ("hasRole('ROLE_USER')" )
162
175
@ RequestMapping (value = "/" + USER_URL , method = RequestMethod .GET )
163
- public String requestUserCode (ModelMap model ) {
176
+ public String requestUserCode (@ RequestParam (value = "user_code" , required = false ) String userCode , ModelMap model , HttpSession session ) {
177
+
178
+ if (userCode == null ) {
164
179
165
- // print out a page that asks the user to enter their user code
166
- // user must be logged in
180
+ // print out a page that asks the user to enter their user code
181
+ // user must be logged in
182
+ return "requestUserCode" ;
183
+ } else {
167
184
168
- return "requestUserCode" ;
185
+ // complete verification uri was used, we received user code directly
186
+ // skip requesting code page
187
+ // user must be logged in
188
+ return readUserCode (userCode , model , session );
189
+ }
169
190
}
170
191
171
192
@ PreAuthorize ("hasRole('ROLE_USER')" )
0 commit comments