I was going through Facebook's authentication mechanism.
and understood the client side, server side and desktop app processes.
But I couldn't understand the iOS tutorial.
https://developers.facebook.com/docs/mobile/ios/build/
Where it talks about How Facebook SDK for iOS gracefully falls back to diff ways of authentication depending upon whats installed on users phone.
From the tutorial I understood that,
The API checks if facebook app is installed or not and if its
there..it opens it and entire login process n pemission giving is
done there and then the app redirects back to our app passing the
authorization token, expiration, and any other parameters the
Facebook OAuth server may return.
If FB app is not installed, Safari is opened and process happens
there and access token is taken out of its cookies once it redirects
back to the app.
And if iOS doesnt support multitasking, we cant open safari or any
other app along with it,then it opens a UIWebView and carry on and
access the token from its urlbar's fragment area after #.
I got the third way which is what we do with a desktop app in .NET or air.
Can anyone explain the first n second ways ?
How can one app redirect the control to the other and how it can pass data to it.
and regarding the second way, how can the app read Safari's cookies ?
It does it by opening a URL using UIApplication – openURL: and that URL will check if the facebook app is installed by using their custom URL ( http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html ). When that happens facebook then redirects back to your app using the same mechanism.
Read the documentation under //// private here: https://github.com/facebook/facebook-ios-sdk/blob/master/src/Facebook.m
Related
I've built a web application using react.js and converted that to an iOS application using Cordova. LinkedIn login session is not being stored on localStorage in the mobile app but working fine in web app.
Once user login with LinkedIn, app will be redirected to a web page where we are storing the token and other user information in the LocalStorage.
When user closes(remove from background) and opens the app again, Session Token is empty in LocalStorage. Same thing works fine in web app(May be its because of caching).
Note: When user try to login with credentials(Username and Password), we are calling the same class to store the token and user data. In this case, mobile app is able to find the stored data after reopen the application.
I'm not able to debug the iOS app using xCode. Console.logs and break points doesn't work.
It will be great if someone can guide me with what I'm missing in the storing process or at least guide me to debug the iOS app on xCode.
Thanks In Advance!!!
I am working on PWA app using React-Redux. Using Adal for azure login. 2 factor authentication is enabled for the user.
Problem is on iOS when the user gets the Pin for 2 FA and switches away from app to see the pin in the messaging app and comes back to PWA app, PWA refreshes and takes the user to login page.
I have searched everywhere and could not find any answer to this.
iOS 12.2 was just released 2 days agao and it fixed the problem:
PWAs (Progressive Web App) have a new lifecycle and on most normal situations, the state of your app will be saved and restored between sessions.
A link to an external site opens in a “PWA In-App browser” instead of Safari and if the external site links to the PWA’s scope again, the navigation goes back to the PWA. Now we can log in users on external origins within a PWA (such as with OAuth). Credit to Medium article
Try maintaining state using IndexedDB. This will work with a PWA on iOS Safari. Another advantage of using indexedDB is that pages on the same domain that live outside of the PWA can write to IndexedDB and that data can be read, any encryption signature verified, and used by the PWA, which also has access to IndexedDB.
We have an ios app that uses native Facebook login just fine.
Then we also have a website (app is basically an optimized client for it) where people can login via Facebook too. When they open our website in mobile safari, they are directed to Facebook pages to authenticate there and it works, but.. it is still far from native and users have to retype credentials they often have in ios already.
So could it be possible to to somehow launch system fb authentication for just a web page (maybe using some clever URL schema?) and get granted token back to web?
Difficult way
As described here http://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified#mobile-apps you could find URL scheme to trigger the native iOS app for app authorization:
fbauth://authorize?redirect_uri=[redirect_uri]&client_id=[client_id]&response_type=token
But if you call that link it's not possible to have a redirection. You could try to hack that redirection but maybe you could not find a way out.
A secure way to solve that problem is to use a SSO token to authenticate user on your App when he logs in, and next on Safari take a redirection, with a custom url to your APP, that do as bridge to FB App via Token stored in your APP. After FB authentication you can directly redirect user back to your landing page in Safari. As said by #Lego it's an alternative way to direct authenticate that could be made by going deep to custom URL used by FB.
No, it is not yet possible to directly authenticate the user via the native Facebook App, but it's possible to authenticate the user using a custom URL scheme which opens your native iOS app which then handles the authentication flow:
The user authenticates natively with your iOS App. You then store the user login (not password) in your app (i.e. using NSUserDefaults).
Then the user opens your web page in Mobile Safari. You redirect the user via a custom url scheme to your app (i.e. using myapp://authenticate). Apple documentation on implementing custom URL schemes: click
Now, if you have an active FB session in your iOS app, you can either directly redirect the user back to your landing page in Mobile Safari, passing the access token via url get parameter or you first re-authenticate the user, displaying a login view with the user name pre-filled, which you have stored in your iOS app before (step 1) and then redirect the user to your landing page, again all depending on session state and your security needs.
For opening face book app you can use Custom URL scheme. But i am not sure if u can authenticate user from it. In case if you could also then it will be confined up to the fb account which is already configured on that device app .so better try to use face book api or something
I don't get your question exactly but i think as per your question you want to create fb app Login in safari or in your custom web view.
is this perfect ?
as per my knowledge web view is different thing and native app is different thing.
if you are Login in web view then no need to check anything token or other thing because it will give you Logout thing there.
but if you are Login in your application then "developer.facebook.com" will definitely help you.
and yes, you will do most of the thing in your app as native facebook app do.
Hope it help....
Right now I'm using a Facebook SDK to share posts from my application. The problem is that this sdk pops up a webview inside my app and asks the user to log in. There has to be a better way.
Can I send the share information to the facebook app on the users device (If they have it installed)? Or at least leverage the facebook app to check credentials? If people have to sign in to share, they probably won't do it..
The latest Facebook SDK 3.5 includes a native share dialog. If you follow the authentication workflow according do the documentation and the phone is on iOS 6.0 you should not get a UIWebView during authentication, instead you will get a UIAlertView.
Facebook login process would use WebView only in a few cases. Some of them are:
1) You are asking it to do so explicitly, by using - (void)openWithBehavior:(FBSessionLoginBehavior)behavior completionHandler:(FBSessionStateHandler)handler; which, I think, is not your case.
2) If there is no Facebook app installed on the device, FB SDK falls back to using WebView login window.
3) Probably, this is your case. If you are requesting publish permissions on the first attempt to open FB session, FB SDK will also fall back to old login flow envolving WebView. In the new login flow, FB session is supposed to be open with read permissions first (in that case, FB will use fast app switching or native iOS FB login):
+ (BOOL)openActiveSessionWithReadPermissions:(NSArray*)readPermissions allowLoginUI:(BOOL)allowLoginUI completionHandler:(FBSessionStateHandler)handler;
Then, you should ask additional publish permissions from the user:
- (void)requestNewPublishPermissions:(NSArray*)writePermissions defaultAudience:(FBSessionDefaultAudience)defaultAudience completionHandler:(FBSessionRequestPermissionResultHandler)handler;
That way, user will not need to log in (if he is logged in FB app already), but there will be inconvenience of double switching from your app to FB (though it works rather fast lately).
I was looking for a cleaner way to get publish permissions with FB Single Sign On on the first call, but unfortunately didn't find anything working yet.
This is the link for Facebook's iOS tutorial.
https://developers.facebook.com/docs/mobile/ios/build/
Can any one please explain what does this mean :
"If the device is running in a version of iOS that supports multitasking, but it doesn't have the Facebook app of version 3.2.3 or greater installed, the SDK will open the authorization dialog in Safari. After the user grants or revokes the authorization, Safari redirects back to the calling app. Similar to the Facebook app based authorization, this allows multiple apps to share the same Facebook user access_token through the Safari cookie."
Most of the posts say,like this one:
https://stackoverflow.com/questions/531712/reading-cookies-using-xcode-on-the-iphone
because of the sandbox environment of iOS one cannot access safari cookies, then how is this possible ?
and if its possible, How can multiple apps use the same access token. According to me different apps might have different permissions.
Your app does not read the cookie in that case. I think it just opens up a URL in Safari. Then some Facebook code which is run in Safari checks whether a valid Facebook session exists and then calls a callback function in your app. Of course all the access tokens and with them the different permissions for all the different apps on the device are saved separately in the facebook session so that the apps do not share the permissions. Only the user is saved in the session (most likely there is only one user who uses the mobile device), so that he doesn't have to login over and over again. He instead just clicks on 'login' or 'no, I'm not So and So'.