Skip to content

Commit e371ad3

Browse files
committed
fixed checking of refresh token permissions in client service, clients can now request either refresh_token grant type or offline_access scope and it will work. added checkbox to dynreg page for ease-of-use
closes mitreid-connect#734
1 parent 56344fa commit e371ad3

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

openid-connect-server-webapp/src/main/webapp/resources/template/dynreg.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ <h1><%-(client.client_id == null ? 'New' : 'Edit')%> Client</h1>
264264
<label class="checkbox">
265265
<input id="grantTypes-redelegate" type="checkbox" <%-($.inArray("urn:ietf:params:oauth:grant_type:redelegate", client.grant_types) > -1 ? 'checked' : '')%>> redelegate
266266
</label>
267+
<label class="checkbox">
268+
<input id="grantTypes-refresh_token" type="checkbox" <%-($.inArray("refresh_token", client.grant_types) > -1 ? 'checked' : '')%>> refresh token
269+
</label>
267270

268271
</div>
269272
</div>

openid-connect-server/src/main/java/org/mitre/oauth2/service/impl/DefaultOAuth2ClientDetailsEntityService.java

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,28 @@ public ClientDetailsEntity saveNewClient(ClientDetailsEntity client) {
108108
client = generateClientId(client);
109109
}
110110

111-
// if the client is flagged to allow for refresh tokens, make sure it's got the right granted scopes
112-
if (client.isAllowRefresh()) {
113-
client.getScope().add(SystemScopeService.OFFLINE_ACCESS);
114-
} else {
115-
client.getScope().remove(SystemScopeService.OFFLINE_ACCESS);
116-
}
111+
// for refresh tokens, ensure consistency between grant types and tokens
112+
ensureRefreshTokenConsistency(client);
117113

118114
// timestamp this to right now
119115
client.setCreatedAt(new Date());
120116

121117

122118
// check the sector URI
119+
checkSectorIdentifierUri(client);
120+
121+
122+
// make sure a client doesn't get any special system scopes
123+
client.setScope(scopeService.removeRestrictedScopes(client.getScope()));
124+
125+
ClientDetailsEntity c = clientRepository.saveClient(client);
126+
127+
statsService.resetCache();
128+
129+
return c;
130+
}
131+
132+
private void checkSectorIdentifierUri(ClientDetailsEntity client) {
123133
if (!Strings.isNullOrEmpty(client.getSectorIdentifierUri())) {
124134
try {
125135
List<String> redirects = sectorRedirects.get(client.getSectorIdentifierUri());
@@ -136,16 +146,13 @@ public ClientDetailsEntity saveNewClient(ClientDetailsEntity client) {
136146
throw new IllegalArgumentException("Unable to load sector identifier URI: " + client.getSectorIdentifierUri());
137147
}
138148
}
149+
}
139150

140-
141-
// make sure a client doesn't get any special system scopes
142-
client.setScope(scopeService.removeRestrictedScopes(client.getScope()));
143-
144-
ClientDetailsEntity c = clientRepository.saveClient(client);
145-
146-
statsService.resetCache();
147-
148-
return c;
151+
private void ensureRefreshTokenConsistency(ClientDetailsEntity client) {
152+
if (client.getAuthorizedGrantTypes().contains("refresh_token") || client.getScope().contains(SystemScopeService.OFFLINE_ACCESS)) {
153+
client.getScope().add(SystemScopeService.OFFLINE_ACCESS);
154+
client.getAuthorizedGrantTypes().add("refresh_token");
155+
}
149156
}
150157

151158
/**
@@ -230,30 +237,10 @@ public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDet
230237
}
231238

232239
// if the client is flagged to allow for refresh tokens, make sure it's got the right scope
233-
if (newClient.isAllowRefresh()) {
234-
newClient.getScope().add(SystemScopeService.OFFLINE_ACCESS);
235-
} else {
236-
newClient.getScope().remove(SystemScopeService.OFFLINE_ACCESS);
237-
}
238-
240+
ensureRefreshTokenConsistency(newClient);
241+
239242
// check the sector URI
240-
if (!Strings.isNullOrEmpty(newClient.getSectorIdentifierUri())) {
241-
try {
242-
List<String> redirects = sectorRedirects.get(newClient.getSectorIdentifierUri());
243-
244-
if (newClient.getRegisteredRedirectUri() != null) {
245-
for (String uri : newClient.getRegisteredRedirectUri()) {
246-
if (!redirects.contains(uri)) {
247-
throw new IllegalArgumentException("Requested Redirect URI " + uri + " is not listed at sector identifier " + redirects);
248-
}
249-
}
250-
}
251-
} catch (UncheckedExecutionException ue) {
252-
throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri());
253-
} catch (ExecutionException e) {
254-
throw new IllegalArgumentException("Unable to load sector identifier URI: " + newClient.getSectorIdentifierUri());
255-
}
256-
}
243+
checkSectorIdentifierUri(newClient);
257244

258245
// make sure a client doesn't get any special system scopes
259246
newClient.setScope(scopeService.removeRestrictedScopes(newClient.getScope()));

0 commit comments

Comments
 (0)