How to remove all application data on react native? - android

How to remove all application data on react native?
Not only AsyncStorage.clear().
I mean deleting application data like through settings > application.
I have faced EUNSPECIFIED error code with react-native-fbsdk.
First I logged in with my facebook account,
Second I logged out from it,
Third I relogin with this account (It works well)
And then I logged out again,
And I tried to log in with another facebook account,
But I faced EUNSPECIFIED error.
But after deleting all app data (not uninstall) through settings > application,
I can login with another facebook account.
I have to delete all applilcation data when logged out from my react native application.
OR
I have to fix this react-native-fbsdk's bug (or I guess fbsdk is caching some data....)
Already I put AsyncStorage.clear() when logout, No changes..
Appreciate for your help...

I had this problem with FBSDK as well and the problem is that when you login with facebook, the SDK creates an AccessToken linked to the old user. Therefore, when you try to login with another account, it throws this weird error message.
What you have to do is to logout the user on the fbAPI. The code below is how you do it:
// Remove FbAccessToken when the user logout.
logoutFromFB(){
if (AccessToken.getCurrentAccessToken() != null) {
LoginManager.logOut()
}
}
I hope it helps!

Related

SignOut issue from Microsoft Active Directory SDK for Android

I am using Microsoft Azure Active Directory SDK for Authentication in my Android App. SignIn & Graph API implementation is working fine. But when I am calling the signout method of SDK. It signout me from the app. But when I pressed again login, it opens the browser overlay for SignIn.
There Microsoft page shows me my last account as an item to pick. Once I clicked on the item it allows me to log in the app without asking password again.
So it seems Microsoft does not clean the User account instance in the browser which opens by SDK.
I tried to clean Cookies & Cache in the signout callback method. but No success yet.
Has anybody faced such a problem before? Some days before I faced such a problem with the OKta Authentication also. It was also an open browser overlay for login.
It's worked for me,
Clear your cookies and shared preferences also
Clear browser cookies after logout
private fun logoutFromMS(){
// Clear Microsoft pref
requireActivity()
.applicationContext
.getSharedPreferences("com.microsoft.aad.adal.cache", 0)
.edit()
.clear()
.apply()
requireActivity()
.applicationContext
.getSharedPreferences("WebViewChromiumPrefs", 0)
.edit()
.clear()
.apply()
val cookieManager: CookieManager =
CookieManager.getInstance()
cookieManager.removeAllCookies { data ->
Timber.d("DATA:removeAllCookies: $data")
}
cookieManager.removeSessionCookies { data ->
Timber.d("DATA:removeSessionCookies: $data")
}
cookieManager.flush()
}
Here is a thread discussing something similar. And is likely what you are running into. https://github.com/Azure-Samples/active-directory-xamarin-native-v2/issues/86
Mainly that you can clear the token cache for the embedded browser, but not from the chrome browser. and that is sort of by design.
basically you are logging out of your app, Not out of azure ad. if there are other apps or sites or email accounts using that same login, then you will kick them all out which is not necessarily a good thing. In the thread there is a mention of something similar but with google signin: How to Logout of an Application Where I Used OAuth2 To Login With Google? this gives you some quick and dirty example of how to log off of the authprovider, basically calling the logout endpoint. you would have to do something similar if you wanted to do it for azure.

Firebase Facebook Login Even If Cleared Cache and Logout after Uninstall App

My app has authentication via Facebook/Firebase. Whole application is made by fragments and ofc one activity.
Case (simply):
There are 2 fragments : howToFragment and mainFragment .
I uninstalled app after clearing cache and signout from firebase and facebook.
In howToFragment, i check that is there already a user logged-in or not.
override fun onStart() {
super.onStart()
firebaseAuth = FirebaseAuth.getInstance()
val user = firebaseAuth!!.currentUser
if (user != null) {
this.view?.let { Navigation.findNavController(it).navigate(R.id.action_howtoFragment_to_mainFragment) } // This will be navigated to main fragment.
}
/*firebaseAuth!!.signOut()
LoginManager.getInstance().logOut()*/
}
Then i install app in debug mode. I see that user is logged-in and navigated to MainFragment. When i check the id of user, i see that it is my main facebook account id (ofc i made so many test with it, but never used for 2 week, it is not even logged-in facebook app)
After that, i close the app (not uninstall). When i open it again, i see that there is no signed in user, firebaseAuth is null. (i dont know how it signout, because there is no code for sign out in app) But facebook is log-in status.
I guess, i miss an obvious point, but what?
Is there a default user, or mis cache?
While i was trying to find solution, i got this question&answer.
Answer of question

Destroy Facebook session completely in a custom Android Application using Facebook SDK 4.x.x

I am just new to Android Application and trying my hands on implementing Facebook login within my app. Successfully implementation of login but logout causes some trouble.
The first time I logged in it requested for my details and then signed in.
Next time I do the same it no more asks for my details, by default it logs me in with account.
What if I want to sign in with different user?
I have searched the net for solution and found out that -
- I cannot use Session as they were available only till Facebook SDK 3.X.X not for SDK 4.X.X
- I have tried calling LoginManager.getInstance().logOut();
(But I still have doubts where to use it.)
- I have also tried
new GraphRequest(AccessToken.getCurrentAccessToken(),"/me/permissions/", null, HttpMethod.DELETE,
new GraphRequest.Callback(){
#Override
public void onCompleted(GraphResponse graphResponse) {
LoginManager.getInstance().logOut();
}
}).executeAsync();
and I have also tried doing this :
` AccountManager am = AccountManager.get(context);
Account[] localAccounts = am.getAccounts();
for (int i=0; i<localAccounts.length; i++){
if (localAccounts[i].type.equals("com.facebook.auth.login")){
am.removeAccount(localAccounts[i], null, null);
}
}`
So it'll be really great if somebody could guide me properly on how to carry out a successful logout operation on Facebook, I'll be highly obliged.
Thanks in advance :)
The SDK will use either of two options to let the user log in to your app on Android:
using the native login dialog (which is powered by the Facebook app that is installed on the device)
using a webview-based dialog if the Facebook app is not installed on the device.
Both options depend on you being signed into Facebook in another app (your browser/your native Facebook app).
If you want to log into your app as a different user (there is really no need, because android system user profiles should be considered personal and individually owned), you need to go to the app you use for Facebook (native Facebook app/browser) and switch to a different profile there. After that you should be able to log into your app with that other profile.
Other than that, it is not your app's job to log people out of their Facebook.

Is it possible to clear cache in iOS and Android webkit?

The sdk I am using for my app calls up a webview that loads Facebook's login oauth login screen. I can't find a way of logging the user out so that they can login as a different Facebook user as the view always loads with the credentials of the first user. My only solution is to uninstall the app.
I have been using 'https://graph.facebook.com/me/permissions?method=delete&access_token=', which does in fact remove the user from my app, by I think the webkit cache keeps the last access_token around and just tries to reauthenticate it.
I haven't seen any apps so far that let you fully logout and login as a different user when using Facebook to authenticate.
you can use this at time of logout
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie *each in cookieStorage.cookies) {
// put a check here to clear cookie url which starts with twitter and then delete it
if ([[each valueForKey:#"domain"] isEqualToString:#".facebook.com"])
{ [cookieStorage deleteCookie:each]; }
else
{
[cookieStorage deleteCookie:each];
}
}

Android Facebook SDK - How to log in as another user?

I am using the official Facebook SDK for Android in my app.
I have managed to log in successfully,
but the problem arises when I try to log in as another user:
I click on the link that says Logged in as [name]... Not you?
but my application proceeds anyway and posts to my wall...
(as if I have clicked "Allow")
I discovered that clicking on that link throws a facebook exception and retries the request,
so I tried putting a call to logout() in the catch clause.
That made it possible to log in as a new user,
but the next time I run the app,
again, the old user is logged-in...
(Logged in as [old_user]. Not you?)
 
My question is:
Why does the first user's login persist forever
and how to properly handle a click on "Not You" link?
 
My current solution is to always call logout() before authorize() method
but this forces the user to always have to enter his/her email/password
which is not acceptable either.
The facebook access token is saved by SessionStore.
When loggin into Facebook, it will try to restore the access token from SessionStore.
So, I think you can explicitly call facebook.logout and SessionStore.clear() when user exit your application.

Categories

Resources