facebook login give me already authorized this app without automatic returning to the app - iphone

My app should implement login with facebook but I have noticed that every time I want to login the facebook tell me you are already authorize this app , the question if I already authorized the app the facebook should return automatically without pressing the okey button as I saw in other applications ?
see the attached image

I fixed my problem by doing the following steps :
1- login to your facebook as admin to your app.
2- go to https://developers.facebook.com/apps/YOUR_FACEBOOK_APP_ID/summary.
3- go to settings > basic > Native IOS app
4- set the Configured for iOS SSO: to enabled

In iOS/Android the FBAccessToken's expiration time is up to 60 days. When you do FBLogin in your app you get the access token. once you get the token you should not do login again(otherwise you will be prompted already authorized this app since your app has already been given an access token earlier which is not expired ). You should reuse the unexpired access token.
Like this :
if FBSDKAccessToken.currentAccessToken() != nil {
print(FBSDKAccessToken.currentAccessToken().userID)
print(currentAccessToken().tokenString)
//OR call the *FBGraphRequest*
}
Note: for in-App browser login (SVC: Safari View Controller)
see more:
https://developers.facebook.com/blog/post/2015/10/29/Facebook-Login-iOS9/
and
https://developers.facebook.com/docs/reference/ios/4.9/class/FBSDKLoginManager/

You need to make sure that your app has the proper URL Prefix in your Build Settings. Also make sure that the URL Prefix matches your Facebook ID/URL Prefix in the Facebook developer app.
Edit: Your issue is probably that the access_token is expiring so it's have to re-ask for permissions.
This will happen if your application did not request offline_access permissions. In the newer SDK offline_access is deprecated and you now have to extend the access_token.
See this link: https://developers.facebook.com/docs/mobile/ios/build/#extend_token

As this Question is already answered , but i would like to add another helpful answer for Swift 3.0 :
While using FB Login in Swift , i having issue and i previously did this way:
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .systemAccount
As this uses , System account to check user is authorized for login or not . Unless you logout and login through different user , application shows same "Already authorized" message in place of Fresh login . So i used this way and this trick does the work :
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.loginBehavior = .web.
This show Login Screen after logout.
Hope this helps to solve this issue.
Feel free to comment . Thanks.

You should check if there is a current session before logging in with FBSDKLoginManager. Do not use [loginManager logout] before logging in.
if ([FBSDKAccessToken currentAccessToken])
{
NSLog(#"Token is available : %#",[[FBSDKAccessToken currentAccessToken]tokenString]);
// Now get details using graphpath.
} else {
// login with permissions using FBSDKLoginManager and get details using graphpath in completion
}

There is a open bug at facebook.com
https://developers.facebook.com/bugs/190389531089978
But the bug only appears at android, ios works fine.
(btw. same behavior in the foursquare and spotify android app - check it out)

Run your iOS FB application into device not simulator it works fine, and didn't shows the already authorized screen.
Thank you.

Related

Cordova app check if user signed in before closing my app?

i'am trying to made cordova application that need user login to (google + or Facebook)
so i show button for sign in to (google+ or Facebook)
but after i close the app and open it again i need the sign in button hide depending on last signed in account
i need to know how i can check if user signed after closing my application?
ie check if user subscribe with data login to my app or no?
You can check this when your application gets loaded in
function onDeviceReady() {
// Now safe to use device APIs
//Create small function which check for is access toke valid or not
//which returns Boolean true or false
// Else you can use localStorage.isSignInned and once logged in set it as true.
if(isSignInned)
{
//hide buttons
}
}
You can check facebook javascript api here and google javascript api here
It depends upon how you want your application to work.
I am attaching working sample which i created for Facebook for GooglePlus
hope this helps.!

Issues with creating a Facebook App

I have app that sharing photos on Facebook when I put my Facebook App ID in the project.plist I got the login window but not the allow window and there is no picture posted on Facebook which I think it is related to a mistake in creating the Facebook app.
It is the first time I create a Facebook app and I'm not sure what did I miss, let me explain to you what I did so you may be able to help me :
1- I put the app name and the app NameSpace
and create the app ID and secret .
2- Disabled the Sandbox Mode.
3- At the (Native iOS App) I added my app Bundle ID, iPhone App Store ID number, enabled the Facebook login and disabled the Deep linking.
4- At the Permissions : I choose Friends for the Default Activity Privacy, added to Users & Friends Permissions : ( email,user_status,publish actions ),
added to Extended Permissions :( photo_upload )
choose the ( Query String…) for the Auth Token Parameter , and enabled the Authenticated Referrals.
5- At the Advanced : I picked the (web) at Authentication with blank (Deauthorize callback URL) ,
*App Restrictions : Age Restrictions (Anyone 13+) and enabled the Social Discovery.
*Migrations : I only enabled ( Remove offline_acces permission, Explicitly Shared OG Stories and Picture As Dictionary ).
*Security : all blank and set No for (Set Client Token).
Now as you see, do you think I missed something? or did I do something wrong?
Do I need to add a website for the (Mobile Site URL) at the (Mobile Web) in the Basic Settings, if so what URL do I need to add ? is it the URL of my App on itunes ? what do I need to do?
Please I need a help, thanks in advance.
Have you followed all these steps described in Getting Started with the Facebook SDK for iOS?
Have you add -sqlite3.0 to your Other link flag?
And then you should not forget to Add the FBSession to your AppDelegate:
- (BOOL)application:(UIApplication *)applicationopenURL:(NSURL *) urlsourceApplication(NSString *)sourceApplicationannotation:(id)annotation {
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
And also these code in AppDelegate:
- (void)applicationWillTerminate:(UIApplication *)application {
// if the app is going away, we close the session object
[FBSession.activeSession close];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// We need to properly handle activation of the application with regards to SSO
// (e.g., returning from iOS 6.0 authorization dialog or from fast app switching).
[FBSession.activeSession handleDidBecomeActive];
}

facebook-ios-sdk logout question

I have seen a lot of questions here regarding the Facebook Graph API but I still haven't find a solution for simple 'login'/'logout' operations using it. Looks like the Single Sign-On style is causing more confusion than benefits.
I'd like to know if it is possible have the following situation:
Enter in the app (no accessToken/expirationDate created).
Perform a login using SSO by calling authorize:delegate: method (application goes background and the login is made in the 'global' scope (Facebook App/Mobile Safari), asking for the user credentials.
Enter back in the app (now logged in, both accessToken and expirationDate are saved to NSUserDefaults).
Perform a logout by calling the logout: method (now logged out, both accessToken and expirationDate are removed from NSUserDefaults)
Attempt to perform a login again, with exactly the same steps done in 2.
I realize that when I call logout:, I do really log out from Facebook (accessToken is invalidated) from my App scope, not from the global scope (Facebook App/Mobile Safari). In 5.) when I try to log in again, the application goes to background and the login attempt is made again in Facebook App/Mobile Safari as usual, however I'm getting a screen saying that I'm already logged in:
You have already authorized .... Press "Okay" to continue.
Logged in as ... (Not You?).
It's a strange behavior for the user that has just logged out in my App.
My question is:
"Can I really log out from facebook (I mean 'global' scope) from inside my App? This would affect other apps using the facebook credentials too. However, if I can't to do this, how can I avoid the 'strange behavior' describe above?
Thanks
Eduardo,
I feel your pain! I spent the better part of a day working on this issue. I have discovered that when you use SSO and the call:
Called from your code:
[facebook logout:self];
Facebook API method:
- (void)logout:(id<FBSessionDelegate>)delegate {
self.sessionDelegate = delegate;
[_accessToken release];
_accessToken = nil;
[_expirationDate release];
_expirationDate = nil;
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:#"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
if ([self.sessionDelegate respondsToSelector:#selector(fbDidLogout)]) {
[_sessionDelegate fbDidLogout];
}
}
The facebook API does invalidate the access token and expirationdate variables and attempts to delete the mobile Safari cookies, but for some reason, probably Apple's fault the cookies are not really deleted. So when you attempt to login in the next time your mobile Safari will see the cookie and it says:
"You have already authorized .... Press "Okay" to continue. Logged in as ... (Not You?)."
Until either Facebook finds a fix or Apple fixes their broken API we must bypass SSO through Safari. Below are the changes I made to Facebook.m in order to force the old login dialog. If you used these changes they may not work forever but it is my guess that they will work for a very long time. Also to be sure this worked with the most recent facebook API I updated to the latest as of this post (Nov 2011 build).
Called from your code:
[facebook authorize:permissions];
Facebook API method:
- (void)authorize:(NSArray *)permissions {
self.permissions = permissions;
// [self authorizeWithFBAppAuth:YES safariAuth:YES];
[self authorizeWithFBAppAuth:NO safariAuth:NO];
}
If this helps you please up rate this thread and my post to help others find it.
gadildafissh
I'm afraid the answer is no, you can't do this.
Your application is in a sandbox, and can't write outside, where global cookies are (for mobile safari) and Facebook app settings (in Facebook app preferences/cookies I think)
You can only warn your user to logout outside of your app...
...Or you can just not use facebook api SSO, but in app login webform, like I do for other reasons.
If you choose that option this pull request might save you some time ;)
Hii ,
its not possible , the reason is for Single Sign On (SSO) is not to make user login everytime, he logouts , instead if the user logs in anyone of FB enabled apps - it will use that to login again - This is because the device is mostly used by single person in this case only one user can login in Facebook.
you can't control any app outside of your app - for Example - if u login with Gmail & when you open google.com you can see your username there is currently logged In which has SSO,
In new SDK of Facebook, you can set login button loginBehaviour property
Below code in swift ...
let fbButton = FBSDKLoginButton()
fbButton.loginBehavior = .Web
Answer already done, but I just want to clarify it. May be it saved somebody's time.
Go to Facebook.m and change line
[self authorizeWithFBAppAuth:YES safariAuth:YES];
to
[self authorizeWithFBAppAuth:YES safariAuth:NO];
It will cause login window appear inside the app. Logout will work perfect. In other words, it will work as it used to in older versions of OS.
in addition to kishnan94 answer. the objective c version is ;
if you want a modal to open up and ask for facebook credentials seperately from Safari or Facebook app, just use the latest facebook sdk and set the login behaviour
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login setLoginBehavior:FBSDKLoginBehaviorWeb];
this will make the logout process more convenient and less confusing for users without using safari or facebook app accounts.
It seems that this is a bug of Facebook SDK. In a case of the Facebook app is installed on device, access_token is renewed. In other hand, access_token and expirationDate could not be changed. :((

Facebook Logout in iPhone Application

I have integrated the facebook in to my application, From the FB i will be getting the userid and the name of the user and passing it to my own service that will do the validation and allows the respective user to get in to the system. I have got the userid and username from the FB and passed it my service that will do the validation,it allows the user to enter in to app, but my problem is once i logged in , how can i log out from the FB ?
Please let me know your ideas.
Thanks
If you are using the new facebook sdk, then us
[facebook logout:delegate]
Being facebook your Facebook object,and delegate an FBSessionDelegate.
If all goes well your delegate will be called on -(void)fbDidLogout;
That depends on which library you use to connect to facebook.
But I guess that you have a FBSession class that has a logout method...
That logout method also calls deleteFacebookCookies that you could also directly call depending on your needs...
Hope that helps.
If you are using old facebook sdk,then use this code for logout.make FBSession class object and code like this. [FBSessionclassobject logout];
it will delete all FacebookCookies.

iphone twitter and sharing

Has anyone encountered the following error message when sending to Twitter?
"Error: Incorrect signature"
And on the debug console:
<0xf14cf80 SHKTwitter.m:(356)> Twitter Send Status Error: {"request":"\/1\/statuses\/update.json","error":"Incorrect signature"}
So far as I can tell I've followed the install instructions on http://www.getsharekit.com/install/#download and it is working with Facebook, e-mail etc. just not Twitter.
It would be great if someone has seen this error before and goes "aha!".
All I did to enable twitter Sharing is:
Regitered my App as a Twitter APP (Application Type: Browser)
#define SHKTwitterConsumerKey #"My..."
#define SHKTwitterSecret #"My..."
#define SHKTwitterCallbackUrl #"http://www.anything.com/callback" // You need to set this if using OAuth, see note above (xAuth users can skip it)
\#define SHKTwitterUseXAuth 0 // To use xAuth, set to 1
\#define SHKTwitterUsername #"" // Enter your app's twitter account if you'dlike to ask the user to follow it when logging in. (Only for xAuth)
Note that for the callback function you can enter any URL you want. even www.google.com. Just make sure it is the same URL in your code.
The issue is that you're signed into your twitter account, and allowed the app to connect to your profile.
However, days go by, the Key and Secret change, and now you're seeing this error. It's because you have to log out and re-log back into Twitter. I spent waaay too much time finding this out when I created a new Twitter App to hook into (and organize my apps) and found this error.
Basically, ShareKit is saving your login info, auto-logging you in, and getting the error when twitter says the app doesn't have permission to connect to your profile.
Follow these steps to log yourself out and test again :
http://www.getsharekit.com/docs/#logout
Check this previous SO question, it might be able to help you solve the problem:
Twitter API status update always returns "Incorrect signature"