Skip to content

Commit 2429104

Browse files
committed
allow client to specify scopes as part of token request.
1 parent 3734e76 commit 2429104

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

uma-server/src/main/java/org/mitre/uma/token/RequestingPartyTokenGranter.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,36 @@ protected OAuth2AccessToken getAccessToken(ClientDetails client, TokenRequest to
166166

167167
Set<String> ticketScopes = ticket.getPermission().getScopes();
168168
Set<String> policyScopes = result.getMatched().getScopes();
169+
Set<String> requestScopes = tokenRequest.getScope();
170+
Set<String> clientScopes = clientEntity.getScope();
169171

172+
Set<String> permissionScopes = new HashSet<>();
173+
174+
// start with the scopes the client requested
175+
permissionScopes.addAll(requestScopes);
176+
177+
if (permissionScopes.isEmpty()) {
178+
// if none were requested by the client, see if the ticket has any
179+
permissionScopes.addAll(ticketScopes);
180+
}
181+
182+
if (permissionScopes.isEmpty()) {
183+
// if still none are requested, go with what the client is registered for by default
184+
permissionScopes.addAll(clientScopes);
185+
}
186+
187+
if (permissionScopes.isEmpty()) {
188+
// if still none are requested, just go with the matched policy set
189+
permissionScopes.addAll(policyScopes);
190+
} else {
191+
// if there were some requested scopes, make sure the final result contains only the subset given by the fulfilled policy
192+
permissionScopes.retainAll(policyScopes);
193+
}
194+
195+
170196
Permission perm = new Permission();
171197
perm.setResourceSet(ticket.getPermission().getResourceSet());
172-
perm.setScopes(new HashSet<>(Sets.intersection(ticketScopes, policyScopes)));
198+
perm.setScopes(permissionScopes);
173199

174200
token.setPermissions(Sets.newHashSet(perm));
175201

0 commit comments

Comments
 (0)