最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

python - Firebase email confirmation is not working - Stack Overflow

matteradmin6PV0评论

Firebase email confirmation is not working

I have set up email sending in Firebase Auth. The email arrives, but after clicking the generated link, the email_verified flag remains false.

Here is my code for sending the email.

    email_verify_response = requests.post(
        f':sendOobCode?key={FIREBASE_API_KEY}',
        json={"requestType": "VERIFY_EMAIL", "idToken": id_token}
    )
    email_verify_data = email_verify_response.json()

    if 'error' in email_verify_data:
        print("Ошибка при отправке email для подтверждения")
        return firebase_error_response(email_verify_data['error']['message'], 503)
    
    print("Email для подтверждения отправлен")

Here is the code for fetching the users (I run it after clicking the link to check the flag).

    users = []
    
    
    page = auth.list_users()

    while page:
        for user in page.users:
            
            users.append({
                "uid": user.uid,
                "email": user.email,
                "email_verified": user.email_verified,
                "display_name": user.display_name,
                "photo_url": user.photo_url,
                "last_sign_in_timestamp": user.tokens_valid_after_timestamp,
                "created_at": user.user_metadata.creation_timestamp
            })
        
        
        page = page.get_next_page()

    
    return jsonify(users), 200

What could be the problem?

Firebase email confirmation is not working

I have set up email sending in Firebase Auth. The email arrives, but after clicking the generated link, the email_verified flag remains false.

Here is my code for sending the email.

    email_verify_response = requests.post(
        f'https://identitytoolkit.googleapis/v1/accounts:sendOobCode?key={FIREBASE_API_KEY}',
        json={"requestType": "VERIFY_EMAIL", "idToken": id_token}
    )
    email_verify_data = email_verify_response.json()

    if 'error' in email_verify_data:
        print("Ошибка при отправке email для подтверждения")
        return firebase_error_response(email_verify_data['error']['message'], 503)
    
    print("Email для подтверждения отправлен")

Here is the code for fetching the users (I run it after clicking the link to check the flag).

    users = []
    
    
    page = auth.list_users()

    while page:
        for user in page.users:
            
            users.append({
                "uid": user.uid,
                "email": user.email,
                "email_verified": user.email_verified,
                "display_name": user.display_name,
                "photo_url": user.photo_url,
                "last_sign_in_timestamp": user.tokens_valid_after_timestamp,
                "created_at": user.user_metadata.creation_timestamp
            })
        
        
        page = page.get_next_page()

    
    return jsonify(users), 200

What could be the problem?

Share Improve this question asked Nov 17, 2024 at 12:07 MaximMaxim 274 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Once an ID token has been minted it is immutable. So the email_verified claim will only be updated once a new ID token is minted.

In the client-side code that gets the ID token, you can force getting a new token on the user object. If you send that token to the server, the email_verified will then show the up-to-date value.

Post a comment

comment list (0)

  1. No comments so far