Skip to content

Commit 938d7e0

Browse files
committed
Merge branch 'ondrejvelisek/verification-uri-complete'
Closes mitreid-connect#1386
2 parents e3cfb80 + a596cc1 commit 938d7e0

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

openid-connect-common/src/main/java/org/mitre/openid/connect/config/ConfigurationPropertiesBean.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public class ConfigurationPropertiesBean {
6868
private boolean dualClient = false;
6969

7070
private boolean heartMode = false;
71+
72+
private boolean allowCompleteDeviceCodeUri = false;
7173

7274
public ConfigurationPropertiesBean() {
7375

@@ -257,4 +259,18 @@ public boolean isHeartMode() {
257259
public void setHeartMode(boolean heartMode) {
258260
this.heartMode = heartMode;
259261
}
262+
263+
/**
264+
* @return the allowCompleteDeviceCodeUri
265+
*/
266+
public boolean isAllowCompleteDeviceCodeUri() {
267+
return allowCompleteDeviceCodeUri;
268+
}
269+
270+
/**
271+
* @param allowCompleteDeviceCodeUri the allowCompleteDeviceCodeUri to set
272+
*/
273+
public void setAllowCompleteDeviceCodeUri(boolean allowCompleteDeviceCodeUri) {
274+
this.allowCompleteDeviceCodeUri = allowCompleteDeviceCodeUri;
275+
}
260276
}

openid-connect-server-webapp/src/main/webapp/WEB-INF/server-config.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@
6868
<!-- This property turns on HEART compliance mode -->
6969
<!-- <property name="heartMode" value="true" /> -->
7070

71+
<!-- This property allows the server to create and accept fully-composed
72+
user URIs (with the user-code emebedded) for the device flow -->
73+
<!-- <property name="allowCompleteDeviceCodeUri" value="true" /> -->
74+
7175
</bean>
7276

7377
</beans>

openid-connect-server-webapp/src/main/webapp/resources/js/locale/en/messages.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@
510510
"expiredUserCode": "The code that you entered has expired. Return to your device and request a new code.",
511511
"userCodeAlreadyApproved": "The code that you entered has already been used.",
512512
"userCodeMismatch": "There was an error processing the code you entered. Try refreshing the page and returning to your device to request a new code.",
513-
"error": "There was an error processing the code you entered. Return to your device adn request a new code."
513+
"error": "There was an error processing the code you entered. Return to your device and request a new code."
514514
},
515515
"approve": {
516516
"approved": "The device has been approved.",

openid-connect-server/src/main/java/org/mitre/oauth2/web/DeviceEndpoint.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.mitre.oauth2.web;
1818

19+
import java.net.URI;
20+
import java.net.URISyntaxException;
1921
import java.util.Collection;
2022
import java.util.Date;
2123
import java.util.HashMap;
@@ -26,6 +28,7 @@
2628

2729
import javax.servlet.http.HttpSession;
2830

31+
import org.apache.http.client.utils.URIBuilder;
2932
import org.mitre.oauth2.exception.DeviceCodeCreationException;
3033
import org.mitre.oauth2.model.ClientDetailsEntity;
3134
import org.mitre.oauth2.model.DeviceCode;
@@ -134,14 +137,22 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
134137

135138
try {
136139
DeviceCode dc = deviceCodeService.createNewDeviceCode(requestedScopes, client, parameters);
137-
140+
138141
Map<String, Object> response = new HashMap<>();
139142
response.put("device_code", dc.getDeviceCode());
140143
response.put("user_code", dc.getUserCode());
141144
response.put("verification_uri", config.getIssuer() + USER_URL);
142145
if (client.getDeviceCodeValiditySeconds() != null) {
143146
response.put("expires_in", client.getDeviceCodeValiditySeconds());
144147
}
148+
149+
if (config.isAllowCompleteDeviceCodeUri()) {
150+
URI verificationUriComplete = new URIBuilder(config.getIssuer() + USER_URL)
151+
.addParameter("user_code", dc.getUserCode())
152+
.build();
153+
154+
response.put("verification_uri_complete", verificationUriComplete.toString());
155+
}
145156

146157
model.put(JsonEntityView.ENTITY, response);
147158

@@ -154,18 +165,31 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
154165
model.put(JsonErrorView.ERROR_MESSAGE, dcce.getMessage());
155166

156167
return JsonErrorView.VIEWNAME;
168+
} catch (URISyntaxException use) {
169+
logger.error("unable to build verification_uri_complete due to wrong syntax of uri components");
170+
model.put(HttpCodeView.CODE, HttpStatus.INTERNAL_SERVER_ERROR);
171+
172+
return HttpCodeView.VIEWNAME;
157173
}
158174

159175
}
160176

161177
@PreAuthorize("hasRole('ROLE_USER')")
162178
@RequestMapping(value = "/" + USER_URL, method = RequestMethod.GET)
163-
public String requestUserCode(ModelMap model) {
179+
public String requestUserCode(@RequestParam(value = "user_code", required = false) String userCode, ModelMap model, HttpSession session) {
164180

165-
// print out a page that asks the user to enter their user code
166-
// user must be logged in
181+
if (!config.isAllowCompleteDeviceCodeUri() || userCode == null) {
182+
// if we don't allow the complete URI or we didn't get a user code on the way in,
183+
// print out a page that asks the user to enter their user code
184+
// user must be logged in
185+
return "requestUserCode";
186+
} else {
167187

168-
return "requestUserCode";
188+
// complete verification uri was used, we received user code directly
189+
// skip requesting code page
190+
// user must be logged in
191+
return readUserCode(userCode, model, session);
192+
}
169193
}
170194

171195
@PreAuthorize("hasRole('ROLE_USER')")

0 commit comments

Comments
 (0)