Skip to content

Commit 7f6c3b8

Browse files
pendula95vietj
authored andcommitted
Scope from jwt should be correctly propagated to the user principal
1 parent afe9164 commit 7f6c3b8

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

vertx-auth-oauth2/src/main/java/io/vertx/ext/auth/oauth2/impl/OAuth2AuthProviderImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ private User createUser(JsonObject json, boolean skipMissingKeyNotify) {
586586
user.attributes()
587587
.put("rootClaim", "accessToken");
588588

589+
// scope can be present inside JWT and this should be copied to user principal as it is expected from AuthHandler
590+
if (token.containsKey("scope")) {
591+
user.principal().put("scope", token.getString("scope"));
592+
}
593+
589594
} catch (NoSuchKeyIdException e) {
590595
if (!skipMissingKeyNotify) {
591596
// tag the user attributes that we don't have the required key too

vertx-auth-oauth2/src/test/java/io/vertx/ext/auth/test/oauth2/Oauth2TokenScopeTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ public void tokenIsValid(TestContext should) {
124124
} else {
125125
User token = res.result();
126126
should.assertFalse(token.expired());
127-
test.complete();
127+
ScopeAuthorization.create(" ").getAuthorizations(token)
128+
.onComplete(call -> {
129+
should.assertTrue(call.succeeded());
130+
should.assertTrue(PermissionBasedAuthorization.create("scopeA").match(token));
131+
should.assertTrue(PermissionBasedAuthorization.create("scopeB").match(token));
132+
test.complete();
133+
});
128134
}
129135
});
130136
}
@@ -191,7 +197,6 @@ public void tokenIsNotValid(TestContext should) {
191197
should.assertTrue(call.succeeded());
192198
// the scopes are missing
193199
should.assertFalse(PermissionBasedAuthorization.create("scopeX").match(res.result()));
194-
should.assertFalse(PermissionBasedAuthorization.create("scopeB").match(res.result()));
195200
test.complete();
196201
});
197202
});

0 commit comments

Comments
 (0)