Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

96
Visualizações
Handling Firebase auth authentication

I need some help understanding if I am handling the authentication/authorization correctly with Firebase Auth, JS and Python.

Once the user has signed in, I capture the idToken and create a cookie in the browser:

firebase.auth().signInWithEmailAndPassword(email, pass)
.then(({user}) => {
    return user.getIdToken().then((idToken) => {
        if (idToken) {
            document.cookie = "token=" + idToken;
            window.location.assign('/profile');
        } else {
            document.cookie = "token="
        }
    })                    
})
.catch((error) => {
    //handle error here
});

The route /profile should be protected so I created a decorator and I retrieve the cookie and verify it:

id_token = request.cookies.get("token")

if not id_token:
    return redirect(url_for('login'))
try:
    decoded_token = auth.verify_id_token(id_token)
    uid = decoded_token['uid']
except Exception as e:
    print("Exception: {}".format(e))
    return redirect(url_for('login'))

This is working so far but I want to see if this is the ideal situation from a security perspective. Also, what about the onAuthStateChanged? How should I handle it in the case above?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Firebase SDKs send the ID token with each request in the Authorization header, so sending it in a cookie is not going to more or less dangerous than that.

Instead of determining the token in signInWithEmailAndPassword though, I'd instead monitor ID token generation by listening to onIdTokenChanged events and using that moment to update your cookie.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda