Link Firebase phone verified account with Email Password - android

Initially I was having phone OTP verification method to login into my application, later i have added Email / Password method to access the application. How do i merge or link or connect initial phone verified account data to new Email / Password account for the same user?
I want to access same user account by Phone verification and Email / password authentication in firebase realtime database. Is it possible to do?
My firebase structure is like:
- users
-uid
-name: "sam"
-contact: 9999900000
-age: 22
- books
-uid
-bookid
-bookname: "FOCUS"
-price: 355
I should be able to access same uid instead of creating new one by different sign in method. Please help me to do this.
And i also want to avoid everytime login using phone verification, want just by using email password method. phone should not be mandatory

Related

how to get current active android app user email from firebase using firebaseAuth

My app have two user( buyer and seller).
I am tring to get current user email which is buyers but when i run the below code, it shows previously logged in user email which is the seller's one.
String userID= FirebaseAuth.getInstance().getCurrentUser().getEmail();
How to write firebase code to get current active user email.
Use this code snippet FirebaseAuth.getInstance().signOut(); to sign out the current user properly, after successfully signed out you can repopulate your user model from Firebase Auth/login in new user. Hope your problem will be solved with this.
When you go to the Auth > Sign-In Methods page of your project in the Firebase console. do you have One account per email address on or off? If you allow multiple accounts per email address, you will get null for FirebaseUser.getEmail()

How to use linkWithCredential with verifyPhoneNumber?

I create a Firebase Auth user with an email and password
User logs in
User decides to add a phone number to their profile
I call verifyPhoneNumber with an intent to receive a code, call PhoneAuthProvider.getCredential(...) and link resulting AuthCredential to the email and password.
Instead, Android auto retrieves the code, user automatically sign-ins with phone number, their UID changes (it's a new user) and there's no way to link phone credentials back to the original email/password user. To perform a successful link I need to see the SMS code, which is nowhere to be found in case of successful auto sign-in.
????
NO PROFIT.
Any ideas? I tried to set the timeout to 0 for verifyPhoneNumber but auto login still works. Accepting defeat and just link EmailAndPassword credentials to phone number instead of vice versa is not an option, because it will require a massive copying of data from old user record into new, changing all references to this UID everywhere, etc.
verifyPhoneNumber resolves with a PhoneAuthCredential.
It doesn't matter whether the code is auto-retrieved or instant validation occurs. A PhoneAuthCredential is outputted on verifyPhoneNumber completion.
That credential can either be used to signInWithCredential for sign-in or to link to an existing user via linkWithCredential.

Firebase Auth using phone number and password

I am developing Android app using Firebase. Because of that, I want to use Firebase Auth. I have following requirements:
Register/Log in using Facebook
Register/Log in using Email/Password
Register/Log in using Phone Number/Password
The first two are OK, I followed basic tutorials. However, Phone Number / Password is the problem here. Firebase supports only Phone Number/SMS Token for this (its called Phone Auth), but there is no mention about my case. I do not want to hack Firebase and use its realtime database instead of Auth 'database'. Is there any better way to achieve this?
Thank you.
If you have both email and phone of your user and you can use Admin SDK, then perhaps you could exchange users phone number to his email and login with email and password in the background.
Something like this (node.js)
admin.auth().getUserByPhoneNumber(phoneNumber)
.then(user => {
firebase.auth().signInWithEmailAndPassword(user.email, password);
});
Firebase phone authentication is using OTP(one time password). This way there is no hassle for the user to remember the password. Once authenticated, you will be registered. The sms code acts as a password. But that is for one time. Usually , users prefer such behaviour in which you dont have to remember the passwords. If you are still looking for the way you want, see this link and create a custom authentication method.
https://firebase.google.com/docs/auth/android/custom-auth
I had a similar problem -
I combined firebase auth(email + password) with (phone+otp) to get phone+password auth -
https://medium.com/#shivampesitbng/firebase-phone-password-auth-in-vue-b94f15b8fb3d
Use Fake Email:
Well, Firebase doesn't support sign in with mobile number and password but it supports email and password. So you can create a fake email with your mobile number.
Ie: 78******69#yourdomain.com
Also, you can create a complete Authentication system using it.
Registration:
Input user mobile and password and proceed to the next page.
Now use Firebase Phone Auth (OTP) to createUser. If process success, link fake email, password credentials in background.
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
auth.getCurrentUser().linkWithCredential(credential);
Login:
Input mobile and password to login. Convert the mobile in fake email and then signInWithEmailAndPassword().
Forget Password:
Redirect the user to a new Page and user Phone Auth to verify the user. If successful, input a new password and change the password of the Email Auth.

Parse.com link fb to ParseUser

Say the following happens:
User logs into my app with fb, creates some objects
User logs out
User logs in with email/password, creates some objects
User auth's with fb and ParseUser.getCurrentUser() is linked to fb account
User logs out
User logs in with fb.
Which parseobjects will now be loaded for ParseUser.getCurrentUser()? the original objects that were linked to the fb account? or the objects that were linked to the email/pass login account? or both?
Parse.com has special object (class) called "User"
This class has special field - "authData" where you can link your Facebook or Twitter account. (Please, see snapshot attached).
There are different mechanism for login your current Parse user:
1) via username and password
[PFUser logInWithUsernameInBackground:#"User Name"
password:#"Password"
2) via Facebook
[PFFacebookUtils logInWithPermissions:permissionsArray block:
for link PFUser with FB:
[PFFacebookUtils linkUser:[PFUser currentUser] permissions:permissionsArray block:
So, return to your question, this scenario should be avoided on "Sign Up/Sign In" phase. During registration you can ask "email/phone number" and use this data as starting point.
OR
Sign Up via Facebook than ask email (or move this possibility to User Profile Settings).
In other case, you will have 2 users (PFUser class) without possibility to merge them.

Can you use the dropbox api without user athenticate?

Hi I am new in Android and I want know is it possible that you save your dropbox user id and password in constants.Because I don't want the application to ask the user everytime for his password and I need only one account.Is this possible.If yes,then how?
Firstly, The Dropbox API requires the developers to connect to its servers via a sequence of http connections rather than a single connection for security reasons.This way/method of security is known as OAuth.You must have heard the term earlier too.
Secondly, It does not give you any chance to save username and password in your code for security reasons.Rather,the user is prompted to enter his credentials on an authorization page which is remote to the application (i.e hosted # dropbox.com).So it is they who handle the authentication/authorization.What you get as pointers an access token as a return if the user has been successfully logged in (at the page hosted # dropbox.com).
When you have this access token,you do not need the user to provide user name and password again.Instead you just send this access token to the server to confirm to the server that this particular user is already authorized.
Read this page to know the process in detail after marking this as your answer. :smile:
Sorry, I think you can't.
Please see Android Dropbox Sync Api Example with Login ID and Password from Code and How to login into dropbox from my app.

Categories

Resources