@@ -1150,6 +1150,33 @@ public void customClaimsVerifyTenant(
1150
1150
// [END verify_custom_claims_tenant]
1151
1151
}
1152
1152
1153
+ public static void setCustomUserClaimsTenant (TenantAwareFirebaseAuth tenantAuth ,
1154
+ String uid ) throws FirebaseAuthException {
1155
+ // [START set_custom_user_claims_tenant]
1156
+ // Set admin privilege on the user corresponding to uid in a specific tenant.
1157
+ Map <String , Object > claims = new HashMap <>();
1158
+ claims .put ("admin" , true );
1159
+ tenantAuth .setCustomUserClaims (uid , claims );
1160
+ // The new custom claims will propagate to the user's ID token the
1161
+ // next time a new one is issued.
1162
+ // [END set_custom_user_claims_tenant]
1163
+
1164
+ String idToken = "id_token" ;
1165
+ // [START verify_custom_claims_tenant]
1166
+ // Verify the ID token first.
1167
+ FirebaseToken decoded = tenantAuth .verifyIdToken (idToken );
1168
+ if (Boolean .TRUE .equals (decoded .getClaims ().get ("admin" ))) {
1169
+ // Allow access to requested admin resource.
1170
+ }
1171
+ // [END verify_custom_claims_tenant]
1172
+
1173
+ // [START read_custom_user_claims_tenant]
1174
+ // Lookup the user associated with the specified uid in a specific tenant.
1175
+ UserRecord user = tenantAuth .getUser (uid );
1176
+ System .out .println (user .getCustomClaims ().get ("admin" ));
1177
+ // [END read_custom_user_claims_tenant]
1178
+ }
1179
+
1153
1180
public void generateEmailVerificationLinkTenant (
1154
1181
TenantAwareFirebaseAuth tenantAuth ,
1155
1182
String email ,
0 commit comments