title: FastAPI: security with firebase token
body: <p>I'm following <a href="https://fastapi.tiangolo.com/tutorial/security/first-steps/" rel="noreferrer">this tutorial</a> to create an api backend.</p>
  <p>I use firebase authentication:</p>
  <ul>
  <li>user input email and password at frontend
  <ul>
  <li>front sends the info to firebase</li>
  <li>firebase auth user and return token</li>
  <li>front stores the token</li>
  </ul>
  </li>
  <li>for any url that needs auth, front sends the token in <code>Authorization</code> header (<code>Bearer xxx</code>)</li>
  <li>server side firebase checks the token</li>
  </ul>
  <p>The tutorial shows how to do this with a password:</p>
  <pre class="lang-py prettyprint-override"><code># creating a dependency
  oauth2_scheme = OAuth2PasswordBearer(tokenUrl=&quot;token&quot;)
  
  async def get_current_user(token: str = Depends(oauth2_scheme)):
      user = fake_decode_token(token)
      return user
  </code></pre>
  <p>But since I'm using firebase, there is no <code>/token</code> for getting token with password.</p>
  <p>I can parse the token by creating a custom dependency, like:</p>
  <pre class="lang-py prettyprint-override"><code>async def parse_token(auth_token:str = Header(...)):
      token = auth_token.split(' ')[1]
      return token
  
  async def get_current_user(token: str = Depends(parse_token)):
      # check the token with firebase auth
      user = auth.verify_id_token(token)
      return user
  </code></pre>
  <p>But now I have to check everything and return exceptions manually.</p>
  <p>Is there a FastAPI way to do this?</p>