1616
1717package org .mitre .oauth2 .web ;
1818
19+ import java .net .URI ;
20+ import java .net .URISyntaxException ;
1921import java .util .Collection ;
2022import java .util .Date ;
2123import java .util .HashMap ;
2628
2729import javax .servlet .http .HttpSession ;
2830
31+ import org .apache .http .client .utils .URIBuilder ;
2932import org .mitre .oauth2 .exception .DeviceCodeCreationException ;
3033import org .mitre .oauth2 .model .ClientDetailsEntity ;
3134import org .mitre .oauth2 .model .DeviceCode ;
@@ -134,11 +137,16 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
134137
135138 try {
136139 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+
138145 Map <String , Object > response = new HashMap <>();
139146 response .put ("device_code" , dc .getDeviceCode ());
140147 response .put ("user_code" , dc .getUserCode ());
141148 response .put ("verification_uri" , config .getIssuer () + USER_URL );
149+ response .put ("verification_uri_complete" , verificationUriComplete );
142150 if (client .getDeviceCodeValiditySeconds () != null ) {
143151 response .put ("expires_in" , client .getDeviceCodeValiditySeconds ());
144152 }
@@ -154,18 +162,31 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
154162 model .put (JsonErrorView .ERROR_MESSAGE , dcce .getMessage ());
155163
156164 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 ;
157170 }
158171
159172 }
160173
161174 @ PreAuthorize ("hasRole('ROLE_USER')" )
162175 @ 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 ) {
164179
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 {
167184
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+ }
169190 }
170191
171192 @ PreAuthorize ("hasRole('ROLE_USER')" )
0 commit comments