How to create a Firestore safe Document ID based on a string

末鹿安然 提交于 2019-12-11 15:12:56

问题


After some discussion on my question about base64 not being safe for Firestore IDs here I would like to know how one can encode a string to a Firestore "safe" Document ID.

Here is the problem:

  • I am login in users via a custom authentication service.
  • That service provides a username that can contain / that are not safe for the firestore document ids as declared here

I asked about the base64 in another question and that is not safe as it contains /

So what could be a safe way to encode that string without loosing the entropy of the username that the external service provides. That means that there could be a username such as dimi/test1 and another as dimitest1 so just stripping out characters is not an option.

Also since that service has available an open API and my service exposes the document ID's via URLs I would like not to expose the other service usernames via my apps URLS.

Any suggestions?


回答1:


I used Base58 and that was the most safe I could research for



来源:https://stackoverflow.com/questions/56289120/how-to-create-a-firestore-safe-document-id-based-on-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!