ramu11 commented on code in PR #29592:
URL: https://github.com/apache/camel/pull/29592#discussion_r4537104597


##########
components/camel-oauth/src/main/java/org/apache/camel/oauth/JwtTokenValidator.java:
##########
@@ -186,23 +185,43 @@ static OAuthTokenValidationResult validate(
         String issuer = claims.getIssuer();
         long expiresAt = claims.getExpirationTime() != null ? 
claims.getExpirationTime().getTime() / 1000L : 0;
 
-        List<String> scopes = Collections.emptyList();
-        Object scopeClaim = claims.getClaim("scope");
-        if (scopeClaim instanceof String s) {
-            scopes = Arrays.asList(s.split(" "));
-        } else if (scopeClaim instanceof List<?> list) {
-            scopes = new ArrayList<>();
-            for (Object item : list) {
-                scopes.add(String.valueOf(item));
-            }
-        }
+        List<String> scopes = readScopes(claims.getClaim("scope"), 
claims.getClaim("scp"));
 
         Map<String, Object> allClaims = claims.getClaims();
 
         LOG.debug("JWT validated successfully: sub={}, iss={}, exp={}", 
subject, issuer, expiresAt);
         return OAuthTokenValidationResult.valid(subject, issuer, audience, 
scopes, allClaims, expiresAt);
     }
 
+    /**
+     * Reads OAuth scopes from the standard scope claim and the scp claim used 
by some identity providers. Both claims
+     * may be space-delimited strings or collections of scope strings.
+     */
+    private static List<String> readScopes(Object scopeClaim, Object scpClaim) 
{
+        List<String> scopes = new ArrayList<>();
+        addScopes(scopes, scopeClaim);
+        addScopes(scopes, scpClaim);
+        return scopes.isEmpty() ? Collections.emptyList() : 
List.copyOf(scopes);
+    }
+

Review Comment:
   addressed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to