Skip to content

Commit a596cc1

Browse files
committed
Made full URLs for device flow switchable server-wide instead of per-client
1 parent 7ad29ae commit a596cc1

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
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/src/main/java/org/mitre/oauth2/web/DeviceEndpoint.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,21 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
138138
try {
139139
DeviceCode dc = deviceCodeService.createNewDeviceCode(requestedScopes, client, parameters);
140140

141-
URI verificationUriComplete = new URIBuilder(config.getIssuer() + USER_URL)
142-
.addParameter("user_code", dc.getUserCode())
143-
.build();
144-
145141
Map<String, Object> response = new HashMap<>();
146142
response.put("device_code", dc.getDeviceCode());
147143
response.put("user_code", dc.getUserCode());
148144
response.put("verification_uri", config.getIssuer() + USER_URL);
149-
response.put("verification_uri_complete", verificationUriComplete);
150145
if (client.getDeviceCodeValiditySeconds() != null) {
151146
response.put("expires_in", client.getDeviceCodeValiditySeconds());
152147
}
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+
}
153156

154157
model.put(JsonEntityView.ENTITY, response);
155158

@@ -175,8 +178,8 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
175178
@RequestMapping(value = "/" + USER_URL, method = RequestMethod.GET)
176179
public String requestUserCode(@RequestParam(value = "user_code", required = false) String userCode, ModelMap model, HttpSession session) {
177180

178-
if (userCode == null) {
179-
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,
180183
// print out a page that asks the user to enter their user code
181184
// user must be logged in
182185
return "requestUserCode";

0 commit comments

Comments
 (0)