title: How to create a Firestore safe Document ID based on a string
body: <p>After some discussion on my question about base64 not being safe for Firestore IDs <a href="https://stackoverflow.com/questions/56273672/is-base64-a-good-option-for-encoding-custom-document-ids-for-firestore?noredirect=1#comment99189620_56273672">here</a> I would like to know how one can encode a string to a Firestore "safe" Document ID. </p>
  
  <p>Here is the problem: </p>
  
  <ul>
  <li>I am login in users via a custom authentication service. </li>
  <li>That service provides a username that <strong>can contain <code>/</code></strong> that are <strong>not safe for the firestore document ids</strong> as declared <a href="https://firebase.google.com/docs/firestore/quotas#limits" rel="nofollow noreferrer">here</a> </li>
  </ul>
  
  <p>I asked about the base64 in another question and that is not safe as it contains <code>/</code> </p>
  
  <p>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 <code>dimi/test1</code> and another as <code>dimitest1</code> so just stripping out characters is not an option. </p>
  
  <p>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. </p>
  
  <p>Any suggestions? </p>