mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
ID tokens were missing all standard user attributes (e.g. given_name, family_name, email_verified) and every custom:* attribute, leaving only the AWS-internal claims. Copy the stored user attributes into the ID token (id_token only, not access_token) and coerce email_verified, phone_number_verified, and updated_at to their OIDC-spec JSON types instead of leaving them as strings.
This commit is contained in:
1 parent
255b41bca8
commit
8af3611d7a
2 files changed
+122
-3
No files matched your search
@@ -1053,12 +1053,35 @@ public class CognitoService {
|
||||
if (!user.getGroupNames().isEmpty()) {
|
||||
claims.put("cognito:groups", new ArrayList<>(user.getGroupNames()));
|
||||
}
|
||||
if ("id".equals(type)) {
|
||||
addUserAttributeClaims(claims, user);
|
||||
}
|
||||
|
||||
applyClaimsOverride(claims, override, type);
|
||||
|
||||
return signJwt(header, encodeJsonBase64Url(claims), getSigningPrivateKey(pool));
|
||||
}
|
||||
|
||||
private static void addUserAttributeClaims(Map<String, Object> claims, CognitoUser user) {
|
||||
for (Map.Entry<String, String> e : user.getAttributes().entrySet()) {
|
||||
String name = e.getKey();
|
||||
String value = e.getValue();
|
||||
if (name == null || name.isEmpty() || value == null) continue;
|
||||
if (claims.containsKey(name)) continue;
|
||||
switch (name) {
|
||||
case "email_verified", "phone_number_verified" -> claims.put(name, Boolean.parseBoolean(value));
|
||||
case "updated_at" -> {
|
||||
try {
|
||||
claims.put(name, Long.parseLong(value));
|
||||
} catch (NumberFormatException _) {
|
||||
// OIDC requires updated_at to be a JSON number; omit invalid values.
|
||||
}
|
||||
}
|
||||
default -> claims.put(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyClaimsOverride(Map<String, Object> claims, ClaimsOverride override, String tokenType) {
|
||||
if (override == null) return;
|
||||
boolean isAccess = "access".equals(tokenType);
|
||||
|
||||
Reference in new issue
Block a user