iPhone - Add an email account from my app - ios

I want to add an email account from code in the list of accounts to use it later in my app (like iCloud or Gmail accounts). It is possible???
Thank you for advance.
EDIT:
I found the ACAccount class, with this class I will do that??
EDIT 2:
Now, I'm saving the user and password in the keychain. This is a good alternative or no?

It is not possible on a non jailbreaked iOS device. This has to be done by the user manually.
Edit:
If you have gained user and password from the user (legs way) storing it in the keychain is the optimal procedure.

As Volker stated, you can't do it on a non jailbroken device.
The ACAccount class that you refer to is mostly used to get/store credential from a previously configured Facebook, Twitter, Sina Weibo, Trecent Weibo account in your iPhone, which is not the case.
Apple can't grant access to Mail account both read/write.
You can only send an email within your code, by using the Message UI framework.
A valid example on how to use it can be found here.
Hope this helps.

Related

Apple SSO: Random email address for user

I'm interested to implement Apple SSO through AuthenticationService SDK to my app, but there is a thing that bother me: Will Apple generate new random email address for user every time he use Apple SSO in my app? Or once user use Apple SSO, the generated random email address will always assigned to his real email address forever?
Please provide official document/statement from Apple if you have any answer for my question.
Thank you very much, guys!
It is per app per Apple ID as far as I know. If user signs out, and later signs back in he will receive the same email address unless user has explicitly changed it in settings.
Check this out:
https://support.apple.com/en-il/HT210426#change

Cannot get name & email with sign in with Apple on real device

So I'm implementing sign in with Apple, everything goes well on the simulator, I request email, fullName scopes, the authenticate UI shows, and I can get the data, as images shown below:
But when testing on real device (iPadOS 13, iPad 2018), the UI didn't show (it does not asks for name and email on the UI), and I can't get the email, fullName from the response, and I can also confirm that the authorizedScopes are empty, I can only get the user identifier
I believe this is a bug and will file a radar, also posted a discussion on the Apple developer forum (but they usually won't approve my post, I don't know why)
If this is not a bug, can somebody tell me how to fix this?
Thanks
Problem solved! tl;dr
This is an expected behavior
Answered by Apple Engineer
(Original post link: https://forums.developer.apple.com/thread/121496)
Hi aslkdjalksdjasdasd,
This behaves correctly, user info is only sent in the ASAuthorizationAppleIDCredential upon initial user sign up. Subsequent
logins to your app using Sign In with Apple with the same account do
not share any user info and will only return a user identifier in the
ASAuthorizationAppleIDCredential. It is recommened that you securely
cache the initial ASAuthorizationAppleIDCredential containing the user
info until you can validate that an account has succesfully been
created on your server.
Patrick
2019/12/15 Edit
This behavior is also documented on Apple's Sign in with Apple doc, check the documentation.
Ensure that your app relays the credentials and user information to your app servers.
The API collects this information and shares it with your app the first time the user logs in to the app using Sign in with Apple. If the user then uses Sign in with Apple on another device, the API doesn't ask for the user’s name or email again. It collects the information again only if the user stops using Sign in with Apple and later reconnects to your app.
If someone fails in storing "user email", "first-name" first time, then he should follow the following steps:
iPhone Settings -> Apple Id -> Password & Security -> Apple ID logins -> {YOUR APP} > Stop using Apple ID.

How to create an anonymous user account using the users Apple-ID like Day-One does?

A new iOS app should be able to connect to a web service to sync data across devices.
I like the way the diary app Day One solved this:
On registration the user can choose to use mail address to setup a "real" account or to sign in with his Apple ID
When using the "real" account the mail address has to confirmed and a username and password has to be chosen
When using the Apple ID Sign In no additional steps are needed. The app is connected to the web services using some random user ID
When being installed on a new devices it is no problem to re-connect using the Apple-ID method.
Problem 1: How to access the Apple ID?
As far as I know it is not possible for the app to really to access the Apple-ID. Or is there some undocumented way to do this? How is this possible?
I suspect that the app instead might use iCloud to store some token? The iCloud storage is linked to the Apple-ID, thus when installing on a new devices it would be possible to recover the token from iCloud and use it to reconnect.
Or are there other / better methods?
Problem 2: How to handle the authentication?
Let's set Problem 1 aside and assume that we have solved the problem of creating some cross-device username. How could be handle the authentication?
Solution 1: Only the token (Apple ID / iCloud stored username / etc.) is used for authentication. If a request from the app to the server contains a valid username token access is granted.
Solution 2: In addition to the username token a random password is generated when creating the anonymous account. This could be done on the device or on the server. But since the password has to be known on both ends, it need to be transferred from one end to the other at some point.
2a: Trust in the HTTPS connection and transfer the plain password
2b: Use some other method (e.g. Diffie-Hellman) to agree on a common password
On first sight 2b seems to be the most secure solution but is the really the case? The sync data is not encrypted but "only" trusts in the HTTPS connection. Would it add extra security to transfer the password using another method?
Additionally, does it add extra security to use a "password" at all? This is not a password the user selects for his user selected username but a automatically generated password for a automatically generated username / token.
Would it not be the same to just use the generated username token? Only who has access to the token / Apple ID / iCloud account, etc. can access the web service.
So, which solution is the best? Am I missing something and there are better solutions?
As of iOS 12, Apple provide a SDK for developer to access user Apple ID - with user's consent, obviously. Developer can use AuthenticationService SDK to achieve this. Please read more at the documentation. I'm sure this is how Day One app does what you describe.

Facebook login error "User is not allowed to see the application."

Hi: I have submitted my app to the App Store. I have Facebook login feature in my app. When I try to login to Facebook from devices I have I am able to do it seamlessly. However Apple has rejected my app saying " When we tap the Facebook icon to sign up we are taken to mobile Safari where we receive a message that states :
User is not allowed to see the application.: The user is not allowed to see this application per the developer set configuration.
Not sure how will I be able recreate this issue. I installed my app on 3 different devices and was able to login without any errors. I checked my app setting on Facebook Status and Review section of Facebook and I have enabled my general public. Not sure what else I am missing. I just feel very dejected. Can anyone please help me figure this out? I am using parse as my backend service and logging users using parse Facebook login.
Thank you very much!
Another reason this will happen is if you are logged in as a test user from a different app than the one you are trying to sign in to. Facebook test users are app-specific.
Sign out of Facebook and back in with a test user from the correct app.
Go to Safari > http://m.facebook.com > logout
In cases where app sign in with safariviewcontroller, sometimes it contains test user of different app
In my case, I was using wrong facebook application id in the code. So added the correct id & it worked for me.
This issue occurs because Apple testers used the same Facebook test account which was created to test any other app and they did not logged out from that account(forgotten to log out) and that facebook test account doesn't have the permission for the current app in review which is why this issue occurs,
You can follow the given link to replicate the issue by creating an an test account.
http://samwize.com/2014/07/23/error-with-facebook-login-using-test-users/
Steps to create Facebook test account
https://developers.facebook.com/docs/apps/test-users#managetool
We had this problem, and it turned out that the problem app didn't have a namespace set up in the Settings > Basic tab. Creating one is the solution to this.
Recently I have faced this same issue. Presently Facebook doesn't allow you to login from any Facebook id as you app is in development mode. There are 3 possible solutions that work for me:
Use only that id for Facebook Log In Testing with which you are working in Facebook for developer.
In Facebook for Developer-> Login to your Account-> Open app->Roles-> Test Users-> Add->Submit-> Edit on newly created random tester account->"Change Name and Password for this Test User"-> Provide a Name and handy password for testing.->Submit.(Use the given random generated mail id and password for testing Facebook login through your app.
3)In Facebook for Developer-> Login to your Account-> Open app->Roles->Roles->Testers->Add Testers->Provide Facebook Id for the user you want to add as tester->Submit
To get Facebook Id for a valid user. Login to Facebook with the Id you want to make as facebook tester in your development process.Then goto profile and in URL of browser you see id=(some_random_number). Copy that Id and paste it into Add Tester section of Developer account. It will be in pending state until the valid user accept the inviation.
I had something similar when validating to apple too,
I still don't get it now but for some reason the facebook secret id had been erased from the parse configuration.
You must check that point too
I don't know if that was the reason or not but for me this happened only after I signed the application with a release key, so I made the app 'public'. Probably the test users doesn't work for public applications.
We had this problem, and the solution is to use the same FB test accounts that was created from the same FB App. So if the App get rejected from App, then you should send to Apple a FB test account with password.
my side
I was using wrong facebook application id in the code. So added the correct id & it worked for me.

Google account autologin in an iphone app

I am creating an app on iOS that requires a user to login with their google account, but it needs to remember the user for a later time without any user input. For example, if a person quit and reopened the app, it will remember their username and password (or that it has already been verified) and send the user directly into the app. How do I go about accomplishing this?
[[GIDSignIn sharedInstance] signInSilently];
Google uses OAuth for that kind kind functionality. Here's their guide on how to do it.

Resources