[英]How to modify a users firebase authentication token claims?
如果返回的 map 是不可變的 map,我如何更新用戶聲明?
這是 Firebase Auth 文檔中有關如何更新聲明的示例代碼:
UserRecord user = FirebaseAuth.getInstance()
.getUserByEmail("user@admin.example.com");
Map<String, Object> currentClaims = user.getCustomClaims(); //This returns an immutable map
if (Boolean.TRUE.equals(currentClaims.get("admin"))) {
currentClaims.put("level", 10); //This will throw an exception
FirebaseAuth.getInstance().setCustomUserClaims(user.getUid(), currentClaims);
}
拋出異常: UnsupportedOperationException: null 在 com.google.common.collect.ImmutableMap.put(ImmutableMap.Z93F725A07423FE1C889F448B33D21F:4684)
查看該文檔,您似乎可以通過使用新值指定 Map 來設置聲明(即,無需指定您未修改的值)。
您可以簡單地復制 map 以使用HashMap 復制構造函數對其進行修改。
Map<String, Object> immutableCustomClaims = user.getCustomClaims();
Map<String, Object> mutableCustomClaims = new HashMap<>(immutableCustomClaims)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.