Created
January 29, 2018 07:49
-
-
Save 9wick/11034674f4c8c0100b845baa983fc286 to your computer and use it in GitHub Desktop.
Firebase storageでのグループ認証 ref: https://qiita.com/wicket/items/85115c4a6045f4d5fecd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
users:{ | |
userA : { | |
groups : { | |
groupA : true | |
groupB : true | |
} | |
}, | |
userB : { | |
groups : { | |
groupB : true | |
groupC : true | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.updateUserGroupGrant = functions.database.ref('/users/{userId}/groups') | |
.onWrite(event => { | |
return refreshCustomClaims(event.params.userId); | |
}); | |
function refreshCustomClaims(userId){ | |
return admin.database().ref('/users/' + userId + "/groups").once('value').then((snapshot) => { | |
var claim = {}; | |
for (var key in snapshot.val()){ | |
claim[key] = true; | |
} | |
return admin.auth().setCustomUserClaims(userId, claim); | |
}); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service firebase.storage { | |
match /b/{bucket}/o { | |
match /groups/{groupId} { | |
match /{path=**} { | |
allow read, write: if request.auth!=null | |
&& request.auth.token[groupId] == true; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment