Skip to content

Commit dae674a

Browse files
committed
Add possibility to disable verification_uri_complete per client
1 parent 67c87d5 commit dae674a

File tree

8 files changed

+68
-8
lines changed

8 files changed

+68
-8
lines changed

openid-connect-common/src/main/java/org/mitre/oauth2/model/ClientDetailsEntity.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public class ClientDetailsEntity implements ClientDetails {
148148
private Date createdAt; // time the client was created
149149
private boolean clearAccessTokensOnRefresh = true; // do we clear access tokens on refresh?
150150
private Integer deviceCodeValiditySeconds; // timeout for device codes
151+
private boolean verificationUriCompleteEnabled = true; // device code optional feature
151152

152153
/** fields for UMA */
153154
private Set<String> claimsRedirectUris;
@@ -1051,6 +1052,22 @@ public void setDeviceCodeValiditySeconds(Integer deviceCodeValiditySeconds) {
10511052
this.deviceCodeValiditySeconds = deviceCodeValiditySeconds;
10521053
}
10531054

1055+
/**
1056+
* @return true if verification uri complete in device code flow is enabled, false otherwise
1057+
*/
1058+
@Basic
1059+
@Column(name="verification_uri_complete_enabled")
1060+
public boolean isVerificationUriCompleteEnabled() {
1061+
return verificationUriCompleteEnabled;
1062+
}
1063+
1064+
/**
1065+
* @param verificationUriCompleteEnabled true/false to enable/disable verification uri complete functionality in device code flow
1066+
*/
1067+
public void setVerificationUriCompleteEnabled(boolean verificationUriCompleteEnabled) {
1068+
this.verificationUriCompleteEnabled = verificationUriCompleteEnabled;
1069+
}
1070+
10541071
/**
10551072
* @return the softwareId
10561073
*/

openid-connect-server-webapp/src/main/resources/db/hsql/hsql_database_tables.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ CREATE TABLE IF NOT EXISTS client_details (
132132
allow_introspection BOOLEAN DEFAULT false NOT NULL,
133133
id_token_validity_seconds BIGINT DEFAULT 600 NOT NULL,
134134
device_code_validity_seconds BIGINT,
135+
verification_uri_complete_enabled BOOLEAN DEFAULT true NOT NULL,
135136

136137
client_id VARCHAR(256),
137138
client_secret VARCHAR(2048),

openid-connect-server-webapp/src/main/resources/db/mysql/mysql_database_tables.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ CREATE TABLE IF NOT EXISTS client_details (
131131
allow_introspection BOOLEAN DEFAULT false NOT NULL,
132132
id_token_validity_seconds BIGINT DEFAULT 600 NOT NULL,
133133
device_code_validity_seconds BIGINT,
134+
verification_uri_complete_enabled BOOLEAN DEFAULT true NOT NULL,
134135

135136
client_id VARCHAR(256),
136137
client_secret VARCHAR(2048),

openid-connect-server-webapp/src/main/resources/db/oracle/oracle_database_tables.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ CREATE TABLE client_details (
147147
access_token_validity_seconds NUMBER(19),
148148
refresh_token_validity_seconds NUMBER(19),
149149
device_code_validity_seconds NUMBER(19),
150+
verification_uri_complete_enabled NUMBER(1) DEFAULT 1 NOT NULL,
150151

151152
application_type VARCHAR2(256),
152153
client_name VARCHAR2(256),

openid-connect-server-webapp/src/main/resources/db/psql/psql_database_tables.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ CREATE TABLE IF NOT EXISTS client_details (
132132
allow_introspection BOOLEAN DEFAULT false NOT NULL,
133133
id_token_validity_seconds BIGINT DEFAULT 600 NOT NULL,
134134
device_code_validity_seconds BIGINT,
135+
verification_uri_complete_enabled BOOLEAN DEFAULT true NOT NULL,
135136

136137
client_id VARCHAR(256),
137138
client_secret VARCHAR(2048),

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.",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*******************************************************************************
2+
* Copyright 2018 The MIT Internet Trust Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
17+
package org.mitre.oauth2.exception;
18+
19+
/**
20+
* @author ondrejvelisek
21+
*
22+
*/
23+
public class CompleteVerificationUriDisabledException extends RuntimeException {
24+
25+
/**
26+
* @param clientId of client
27+
*/
28+
public CompleteVerificationUriDisabledException(String clientId) {
29+
super("complete verification uri was attempted to be used but such functionality is not enabled for client " + clientId);
30+
}
31+
32+
private static final long serialVersionUID = -7078098692596870940L;
33+
34+
}

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import java.util.LinkedHashSet;
2525
import java.util.Map;
2626
import java.util.Set;
27-
import java.util.UUID;
2827

2928
import javax.servlet.http.HttpSession;
3029

3130
import org.apache.http.client.utils.URIBuilder;
31+
import org.mitre.oauth2.exception.CompleteVerificationUriDisabledException;
3232
import org.mitre.oauth2.exception.DeviceCodeCreationException;
3333
import org.mitre.oauth2.model.ClientDetailsEntity;
3434
import org.mitre.oauth2.model.DeviceCode;
@@ -50,7 +50,6 @@
5050
import org.springframework.security.core.Authentication;
5151
import org.springframework.security.oauth2.common.exceptions.InvalidClientException;
5252
import org.springframework.security.oauth2.common.util.OAuth2Utils;
53-
import org.springframework.security.oauth2.common.util.RandomValueStringGenerator;
5453
import org.springframework.security.oauth2.provider.AuthorizationRequest;
5554
import org.springframework.security.oauth2.provider.OAuth2Authentication;
5655
import org.springframework.security.oauth2.provider.OAuth2Request;
@@ -138,15 +137,16 @@ public String requestDeviceCode(@RequestParam("client_id") String clientId, @Req
138137
try {
139138
DeviceCode dc = deviceCodeService.createNewDeviceCode(requestedScopes, client, parameters);
140139

141-
URI verificationUriComplete = new URIBuilder(config.getIssuer() + USER_URL)
142-
.addParameter("user_code", dc.getUserCode())
143-
.build();
144-
145140
Map<String, Object> response = new HashMap<>();
146141
response.put("device_code", dc.getDeviceCode());
147142
response.put("user_code", dc.getUserCode());
148143
response.put("verification_uri", config.getIssuer() + USER_URL);
149-
response.put("verification_uri_complete", verificationUriComplete);
144+
if (client.isVerificationUriCompleteEnabled()) {
145+
URI verificationUriComplete = new URIBuilder(config.getIssuer() + USER_URL)
146+
.addParameter("user_code", dc.getUserCode())
147+
.build();
148+
response.put("verification_uri_complete", verificationUriComplete);
149+
}
150150
if (client.getDeviceCodeValiditySeconds() != null) {
151151
response.put("expires_in", client.getDeviceCodeValiditySeconds());
152152
}
@@ -185,6 +185,7 @@ public String requestUserCode(@RequestParam(value = "user_code", required = fals
185185
// complete verification uri was used, we received user code directly
186186
// skip requesting code page
187187
// user must be logged in
188+
model.addAttribute("completeVerificationUriUsed", true);
188189
return readUserCode(userCode, model, session);
189190
}
190191
}
@@ -216,6 +217,10 @@ public String readUserCode(@RequestParam("user_code") String userCode, ModelMap
216217

217218
ClientDetailsEntity client = clientService.loadClientByClientId(dc.getClientId());
218219

220+
if (!client.isVerificationUriCompleteEnabled() && Boolean.TRUE.equals(model.get("completeVerificationUriUsed"))) {
221+
throw new CompleteVerificationUriDisabledException(client.getClientId());
222+
}
223+
219224
model.put("client", client);
220225
model.put("dc", dc);
221226

0 commit comments

Comments
 (0)