Firebase verify email password in cloud function

孤街醉人 提交于 2019-12-10 17:33:59

问题


I have a requirement to accept custom usernames into my site (Requirement from biller with strict limitations of alpha numeric.) And these usernames should be interchangeable with the user's email address for login purposes.

I allow the user to signup and login with their email and password through the standard firebase email password authentication. The user is registered at the biller, who then returns a custom generated username to the application via a postback.

I have created a usernames table that contains the UID of the user each username belongs to (Initially there is the email, and biller generated usernames)

When the user attempts to login, I go to the usernames table and lookup the UID. At this point I would like to use the UID just looked up, and the password supplied by the user to log the user in through the standard firebase authentication system.

I have been unable to find any way to verify the user's password is valid against a looked up user account inside of cloud functions so that I can generate a custom token.

I could lookup the user by the username, find the email, send it back to the client and allow the login to take place with that email and the password the user supplied, but would prefer to avoid it as that will allow usernames and email addresses to be associated with each other by bad actors.


回答1:


In your cloud function you can install and use the firebase package besides firebase-admin, and initialize it as if you were initializing a web page. That way you can use the admin SDK to find the email of the username, and then use firebase from the cloud function to authenticate, using signInWithEmailAndPassword. If it succeeds you can then generate a custom token and send it to the client.

I don't know if this is the best approach but it works.



来源:https://stackoverflow.com/questions/51752457/firebase-verify-email-password-in-cloud-function

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