The goal is the simplify user login/sign up procedure in our iOS application. We have custom backend and our own log in and sign up flow, and we wanted to add Facebook authentication. The story is really the same as described IN THIS POST. We issue our own access tokens, and we need to link Facebook issued access tokens to our database users. We have done exactly the way that is described in that post.
- We used client side issued Facebook access token,
- passed it to server,
- server connected to Facebook graph API and got necessary info from it.
- as a response server send JSON object containing user profile information, which is displayed client side.
The problem that I have is before the point when we get Facebook access token. The first version that I've done, is by using FBSession
as described HERE to log in user and get the access token. It simply displays Facebook log in window, user enters his or her credentials, ask for necessary permissions, and the FBSession
becomes active and I can get token as described HERE.
Starting from iOS 6 user has the ability to log in Facebook in one place, in iOS settings and use that session in all apps to post and get information from Facebook, the only thing that he/she needs to do, is to approve the permissions that are asked by the app, in this way there is no need to log in into each app separately. From UX perspective it's huge improvement, and I wanted to use native iOS Facebook session, exposed by Social Framework, to get the access token and pass it to our backend. I thought it would be easy, and the procedure is described HERE, and here is the quote from there with the lines to get access token
// Get the access token, could be used in other scenarios
ACAccountCredential *fbCredential = [self.fbAccount credential];
NSString *accessToken = [fbCredential oauthToken];
Unfortunately this code doesn't work, [self.fbAccount credential];
returns nil
. And here is a quote from apple documentation about ACAccount
credential
The credential used to authenticate the user of this account.
@property(nonatomic, retain) ACAccountCredential *credential
Discussion - This property is required and must be set before the account is saved. For privacy reasons, this property is inaccessible after the account is saved.
So it's Apple's privacy policy not to allow the stored access token to be accessed by others.
Now this is the dead end. To authenticate towards our server using Facebook, I need Facebook access token, and to improve UX (which client requires) I need to use native Facebook session available from settings menu. Is there any solution to this problem?