phonegap iOS facebook Re-Authentication issue - ios

I am using Cordova 3.4.0 along with the official facebook connect plugin link
The issue is that every time user opens the application. He/She has to press login and then it shows the "App already authorized screen" before the user is able to perform any action. How to prevent this addition of an action in the user flow?
I read that it is basically because the access token isn't stored by the plugin. As a result this action needs to be taken again and again. So I have now stored access token using localstorage but unfortunately don't know how to go about using it.
FB.api('/me/friends?access_token="+access_token+"', { fields: 'id, name, picture' },
Using it in the manner above results in an error saying invalid oAuth access token. Even though I placed an alert before this line to ensure that access_token had a valid value. Any help in this regard would be highly appreciate.
Just to rephrase I don't want the user to be asked to press login button every time they open the application.

Related

How to know user has already done Facebook login at iOS app

I am developing iOS App which use Facebook iOS SDK 4.
When user has already done Facebook login, by doing Facebook login the dialog which shows "user has already approved your app" had be displayed.
So, do not show the dialog. I want to know whether the user has already done Facebook login.
Anyone know the good way? I think accessToken is returned if user once had done Facebook login.
FBSDKAccessToken manage current logged user's accessToken.
According to official Facebook Login guide
"FBSDKAccessToken Represents the access token provided by a successful login. Most important, it provides a global +currentAccessToken to represent the currently logged in user."
The currentAccessToken is a convenient representation of the token of the current user and is used by other SDK components (like FBSDKLoginManager).
According to above you can check either user has valid accessToken or not and based on this you can track call login method otherwise just skip to next flow.
In Facebook the access tokens are per user so you can pass them around apps and they will work. In your case if you can ship an access token from another app you will be able to skip the next logging in and use the API normally.
However I think this this thread will help you.
Things are a little bit different with iOS cause I have done a facebook login on Android and got no such issues.

Salesforce OAUTH implementation

I'm developing Salesforce iOS application.
From application frequently the user has to modify data which is available on Salesforce.com.
When user tap on edit I'm launching salesforce login screen and prompt to enter username and password all the time.
So I have decided to implement SSO using Salesforce Oauth. I have done everything I'm able to receive a access_token once user authenticate with Salesforce.com.
My question is lets say "If the user want to edit a lead with id as 0097hjy7" , URL to edit this lead will be "https://sales.mysalesforce.com/0097hjy7" when this URL launch on browser it prompt to enter username and password again.
How can I navigate the user to "https://sales.mysalesforce.com/0097hjy7" this URL without asking username and password all the time by using the access_token available with me.
Thanks in advance.
I resolved this issue by adding Salesforce iOS SDK to my project and using some classes like SFOauthCoordinator and SFOauthCredentials. At the end we need to prepare a frontDoorUrlWithReturnUrl which is available on "SFAuthenticationManager" class.

Unity-Facebook-Sdk: access token is not for current app id

I'm currently trying to integrate the Unity Facebook SDK into my game. I've downloaded the SDK and trying to test the example that it have. I've insert my app id into the settings and can do the FB Init, and when I press the Login button a pop-up appear asking for the User Access Token. I've done some searching/asking and it seems this is because I'm running it inside the Unity Editor (on mobile it would get the token by itself).
I've heard that I can use the User Token from my Facebook Developer page for testing. However, when I paste the User Token from Facebook Developer->Tools->Access Token and press login, an error appear saying "Access token is not for current app id : XXXXXXXXX". I'm not sure what's wrong here since the app id it shows is the app id I got from Facebook. Is there another User Token that I should be using? Or is there some settings that I need to do first for this to work?
Thank you.
I had this problem.
For me: I had trailing whitespace in the "App id" field in Facebook Settings.
E.g. I had in there "12345 " when I needed "12345".
Got rid of whitespace, all good.
To clarify: I'm assuming you are doing your testing in the editor, which can work you just need to get an access token from the developer site.
I'm going to assume you got the access token from here:
https://developers.facebook.com/tools/accesstoken/
I hate to assume error on your part, so let me know if you can repro this again and we can figure out what went wrong. Also, if I'm way off, please let me know.

iOS Instagram login get Instagram user id?

I am writing an iOS app that needs to do some basic work against the "Instagram API". To login a user I simply hit the "URL":
I do this through a web view. I am able to login the user and get the access token from "Instagram".
So my question is:
I want to be able to know the "Instagram userId" of the user I just logged in.
How can I get the user id?
The user_id is in the first part of access_token
xxxxx.xxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxx
user_id = access_token.split(".")[0];
just enter your user name then user id will display
http://jelled.com/instagram/lookup-user-id
So it turns out to be quite simple, I simply didn't figure out how until now. So once the user logs in through the web view the web view returns the access_token. With that I can call this GET:
https://api.instagram.com/v1/users/self?access_token="the access token I just got from the login"
So, all I have to do is use "self" in the url and that combined with the access token will return the user object which contains the username and more.
http://www.otzberg.net/iguserid/
look down the web and you can look about the Instagram User ID Finder, and you should find by yoursef, It's so easy to find.
* Open Google Chrome and access your Instagram Profile Page, e.g. Lufthansa Instagram Page
* Open the Developer Tools (F12 on Windows; ⌥+⌘+i on OS X)
* Click the Console Option
* At the little command prompt enter: window._sharedData.entry_data.ProfilePage[0].user.id and hit enter
* If you get an error, reload the page and try again
* Until Instagram Changes their page, this will output your User-ID
The easiest way to find an instagram user ID from a username is: https://www.thekeygram.com/find-instagram-user-id/. Works for me every time. And they always keep it updated to support the latest instagram api updates (at least from my experience)

Soundcloud as Oauth Provider: How to make it connect only one time

I'm currently implementing an Oauth consumer service which is going to use Soundcloud as an Oauth service provider as well. But I'm having the following issue with it: Taking Facebook or Twitter example, you go there, you sign in, you fill up the permission form, and you are redirected back to your app. If you go there a second time, and given you are already sign in, you basically skip all steps and are redirected back instantly. That means, Facebook recognized that you already gave permission to that 3rd party service, so it doesn't ask your permission constantly.
And that's what's happening when I use Soundcloud. Basically everytime I redirected the user to the Soundcloud Oauth connect endpoint, the permission form always shows up, even though I already gave permission to that 3rd party service previously. I'm forced to press "connect" every single time, which is a drag from the user perspective (how many times can you give permission to the same entity). My question is: is there a parameter I can use to make soundcloud recognize/validate the previous permission from the user account to that specific 3rd party service? Or is this Soundcloud Oauth design implementation and we have to live with it?
Edit:
Maybe this wasn't clear, but each time I press "connect" in soundcloud, a new access token is being generated and delivered. Since my app uses this access token to identify its users, it doesn't work very well for me that the access token is getting updated everytime I want to log in, making me effectively "sign up" everytime. To sum it up, I want to get the previously attributed token to my account, so I can look up in my database, identify it and log him in.
I'm also looking for a solution which doesn't involve storing state in the client that might get cleaned up.
What you can do is store the user's oauth token in local storage and reuse it in future sessions. That's what happens on soundcloud.com.
A longer explanation:
When you use the Connect flow, the user is authenticated by SoundCloud (either by using username/password, Facebook Connect, or an already-existing session on soundcloud.com), and then when it is successful, your app is given an oauth token for that user. This is passed to the callback page which is registered for your app.
That token is the only piece of information needed to have the user be "logged in". Unless the token expires (by time, or by the user manually revoking it), then you can reuse that in future sessions.
I think I'm a bit confused about your application's design: where and how is the oauth token being used? I think that instead of using the token as an identifier, perhaps the user's permalink might be better? If you have the oauth token, you can find out the permalink by querying api.soundcloud.com/me.

Resources