Firebase Email verification with SMS like Code - ios

It is possible to use email verification with firebase but instead of sending a link they have to click, it should send a code like a sms verification code and i have to check in my ios app (swift based) if they match.

Email verification ensures that the user has access to the email address they claim. Setting an email address to verified by sending a text message is not the same, as you can't know from the receipt of the text message that they have access to the email address.
But as A. Welch commented, you can verify that the user has access to a specific phone number by using Firebase's phone number authentication as documented here: https://firebase.google.com/docs/auth/ios/phone-auth
If neither of those does precisely what you want, you can also roll your own. Send a text message or email with whatever information you want, and use the Firebase Admin SDK to update the user profile.

Related

is unique email address from Apple when performing 'Sign in using Apple' always change?

I am trying to make login using OAuth2 using Apple Sign in. and I need to save the user email to the server.
after reading Sign in with Apple and authenticate with Firebase documentation , it said that
Unlike other providers supported by Firebase Auth, Apple does not
provide a photo URL.
Also, when the user chooses not to share their email with the app,
Apple provisions a unique email address for that user (of the form
xyz#privaterelay.appleid.com), which it shares with your app. If you
configured the private email relay service, Apple forwards emails sent
to the anonymized address to the user's real email address.
apple will generate unique fake email like xyz#privaterelay.appleid.com if the user refuses to share their original email.
if the user logout and then login again, will the fake email will be the same? or apple will generate a new fake email like new123#privaterelay.appleid.com ?

Sign in with Apple ASAuthorizationAppleIDCredential returns random email when user select 'Hide My Email' option for iOS

When I go through the Sign in with apple I am getting first time exact email address and basic details of the user which I want but second time in response there is no email field in response.
My concern is that I want email address of the user so in future I can send notification email to that particular user. but apple gives random created email, in reality that doesn't exists. How to contact to user in future by email?
You might have to register the outbound email with apple, check this for more information on using the private email provided also look at the sign in with apple docs here.
As far as I know the random created email apple gives is actually connected to user's actual mail id. All the mail you send will be forwarded to it. But they can unlink their mail in future. This gives users some privacy and protection from spamming.
When I was finding solution I got to know, we have to pass an email address for following:
The email addresses you register will be able to send and receive messages to and from customers using Appleā€™s private email relay service.
Once I added this I am able to send and receive the emails.
https://developer.apple.com/account/resources/services/configure
Short answer :
You need to add sender email id or domain name into to your developer account.
Add your email and domain name.
Long answer
You need to follow below steps:
Log in with your developer account in https://developer.apple.com
Goto More section. Please refer below screenshot.
Click on configure button. Please refer below screenshot.
Add domain and email address, You want to communicate.
Add email and domain here

Changing email for iOS Firebase user authenticated with email link

So I have an iOS app that uses Firebase, signs users in anonymously initially and then allows them to later add an email address, which is linked to the Firebase user using a call to:
Auth.auth().currentUser?.linkAndRetrieveData(with: credential)
This all works fine but I'm now running into the issue of being unable to update that user's email. I assumed this would work by simply sending another email link to the new email, then calling linkAndRetrieveData with the new credentials.
This, however, gives me a FIRAuthErrorCodeProviderAlreadyLinked error, because the user already has an email address. I would've expected it to just overwrite the existing email. I then tried/considered to solutions:
Unlink the email provider, then relink with the new credentials. First, this seems impossible since the stated "providerId" for an email-link-authenticated user is "Firebase", and when I feed that into unlink it fails. Second, this is bug prone because you could successfully unlink the first email and then have the link of the new email fail.
Use the provided "updateEmail" method - this doesn't work because it assumes email/password authentication, and I'm using email link authentication. Even if this did work, it would mean having an unverified email.
So I'm wondering how to do this, or if it's actually possible that this isn't supported at all. I can't believe this wouldn't be supported since it seems like a very common issue and basically makes email link authentication a nonstarter.
updateEmail() is the method to change email for signed in user, no matter how the user was created or authenticated. You are right that the new email address would become unverified. The sendEmailVerification() method can then be triggered to send a verification email to the user, so they can verify the email address.
The providerID for an email link user should be "emailLink" (Android link, since I couldn't find the iOS version quickly, and the values come from the server anyway).
But note that a linked account will always have a top-level provider of "firebase", and then have the actual values of the linked accounts in the UserInfo elements of the provider array.

Automatically sending an activation key by SMS or email after registration

I'm working on a free iOS app; at the end of the registration (when the user has registered a good phone number and good email address) I want the user to enter a code which he has received on his phone or email.
But the problem is how to send automatically a SMS or an e-mail programmatically that contains the code?
I don't want the user to be redirected to a specific view controller to compose a message by himself (like with MFMessageComposeViewController or MFEmailComposeViewController)
just and only just the same appearance of SMS or email sent to users but with a different activation key (for the keys, I think about auto generated keys stored in a database).
And I think about the same way for forgotten identifiers, the user enter his email address or his phone number in a text field, and a message is automatically sent with the password and the username of the user, if the email address or the phone number entered is already existing in the database, if it is not, it shows an alert view with an error.
Does anyone have an idea for how to do this?
You can use the following services Parse.com + mailgun. Search on Parse.com for a tutorial using mailgun and it should accomplish what you are trying to do. On a side not, be careful when creating an app which does not allow the user to use it until they enter some access code, it is against the Apple rules and could lead to rejection.
I assume you have a server that generates this activation code that is sent to the user.
When the user enters the text field with the code he got it should be sent back to the server with an http request (use NSURLConnection ). The server should response to the http request with approval or error whether the code is right, or send the username and password and any other data the user needs to continue.

Setting default from address of email in ios

In my app, there is an email functionality which should send email from an id, which is not configured with mail app. From address will be like noreplyATgmail.com .. some thing like that.
How can I hard code the from address of an email ?
It's impossible to send email from account where user isn't authorised in.
For your aims it's better implement email functionality on server side that could be authorised to send emails from address that you specified.
As per my comment - you can't, you should use reply-to for that, or send a request to a server to send the email. The from gets set from the selected email address you eventually chose to send the email with.
For example:
mailto:email#email.com?subject=Subject&reply-to=noreply#something.com
I don't think there's anyway to do this using MFMailComposeViewController.

Resources