I'm trying to log out users from my app. In the Firebase API, it says to use [ref unauth];
What exactly is the ref that I'm supposed to unauthorize? Is it a Firebase reference or the user's uid? I've used a Firebase reference, and it doesn't seem to do anything. How do I use this command? What exactly is it supposed to do? I haven't come across a good example.
NSError *signOutError;
BOOL status = [[FIRAuth auth] signOut:&signOutError];
if (!status) {
NSLog(#"Error signing out: %#", signOutError);
return;
}else{
NSLog(#"Successfully Signout");
}
Implement this code you must enjoy that it works for sign out.
The Firebase client manages the connection to its servers behind the scenes and authenticates on that connection instead of per Firebase object. This means that whenever you call for example ref authUser:#"jenny#example.com" password:#"correcthorsebatterystaple" on any Firebase reference, the user is authenticated on all references.
Similarly: when you call unauth on any Firebase reference, the user will be signed out of all references in your app.
Related
Suddenly this behaviour started to happen without changing anything. Basically, I'm able to create users Anonymously or even with Email/Password. I get no error whatsoever, actually I'm able to retrieve the userID. However, when I go to the users list in the console, its always empty.
Auth.auth().signInAnonymously() { user, error in
self.ifNoError(error) {
print("Signed In Anonymously \(user?.user.uid)")
}
}
Results:
Signed In Anonymously Optional("qQazZ3MX8LfQdnlz8F27QDxAT9U2")
Thank you in advance
Did you at any point delete anonymous users from the Firebase console before going live or something like that? That's what I did, not realizing that firebase keeps that user alive on your device...even if you delete the app from the device and re-install. Moreover, it will still work as an accepted anonymous user (even though deleted from the console) UNTIL you force a sign out on a given device. (Oops. TL;DR). Try this.
Sign out the user in your app delegate
FIRAuth *auth = [FIRAuth auth];
NSError *error;
[auth signOut:&error];
Create another anonymous user
[auth signInAnonymouslyWithCompletion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
NSLog(#"Error is %#", error);
NSLog(#"Auth result user id is %#", authResult.user.uid);
}];
In my case, my device now showed a new user UUID and that user shows up in the Firebase console.
Fun fact: This issue doesn't seem arise with Android. My Android app, which shares the same production firestore, happily created a new user after I deleted the app from the device and reinstalled.
I managed to solve the issue by creating a manual user email/password (manually on the console), sign in with it through code, delete it thorough code. Then change the code to sign in again Anonymously. This solved the problem!!
Currently I have a Twitter login that authenticates the user just fine, receiving all the appropriate information for the user necessary for confirming a complete login.
I then am calling the [PFTwitterUtils logInWithBlock:...] method in order to authenticate the user through Parse and populate a new user in _User.
(I am not using just this method to present the Twitter login dialog box as I could not get it to present itself).
Here is the strange part:
On the first time I launch the app, I sign in with Twitter, and then call the logInWithBlock method and receive the following error:
Something went wrong: The operation couldn’t be completed. (NSURLErrorDomain error -1012.)
The strange part is that this issue does not occur at all if I relaunch the app again. The only difference is that upon relaunch I believe the Twitter Account information that I had used before (via browser not accounts) is saved on the device. When I launch the app again, I have it set so that it reloads the previous session: this time the [PFTwitterUtils logInWithBlock:...] works like a charm, creates a new user, etc., without any issue.
NOTE: I have a valid URL saved as the Callback URL on my Twitter App's settings. Also, I hope it is clear that the setup was done correctly given that it works fine on second log in.
Here is the login code I am using:
// Login with Twitter through Parse
[PFTwitterUtils logInWithBlock:^(PFUser *user, NSError *error) {
if (error != nil) {
// Something went wrong
NSLog(#"Something went wrong: %#", [error localizedDescription]);
breakLogin = YES;
[self invalidateSignInTimer];
return;
}
else if (user.isNew){
userObjectID = user.objectId;
[user saveInBackground];
NSLog(#"New User");
}
else if (!user.isNew) {
userObjectID = user.objectId;
[user saveInBackground];
NSLog(#"Returning User. Welcome Back!");
}
}];
I am running out of patience and ideas on why this is happening. If anyone has any ideas please let me know - thanks!
UPDATE:
I noticed that the reason this seems to be happening is such:
The first time i attempt to login there is no PFUser, whereas the second time there seems to be a saved [PFUser currentUser], which allows the [PFTwitterUtils...] method to log in and create the new user.
Yet I am still not sure how to prevent the failure the first time without manually creating a new PFUser and then logging in with Twitter, then PFTwitterUtils...
UPDATE 2
I have resolved this issue with the answer I have provided below. I am leaving this up as I feel this is something that may help others out there in the future.
So after extraneous research, I seemed to have found a solution.
First I made sure that all of my framework files (SKDs, headers, etc) were up to date by removing all of their references from both the project and the library linking.
Second I made sure that all keys and secrets were remade and updated in my
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Lastly I made double checked that I properly went through the set up for Twitter authentication through Parse's website.
BUT what I found to be the only solution rested in the Callback URL.
When specifying the Callback URL in your Twitter Application under "Settings", I had to uncheck the Lock Callback URL option, despite the recommendation by Twitter. (seen below)
I was a little unhappy that all of this trouble derived from something so mundane, however I was at least pleased that solution was in fact resolved without too much trouble. Hopefully this answer helps someone out there struggling with a similar issue.
I am implementing iOS app where I have to implement Respoke SDK for audio and video calling. Audio and video functionality is working fine in development mode but In production mode it gives me error "Api authentication error". I have used this code for production:
[self.client connectWithTokenID:[[aryResult valueForKey:#"data"]valueForKey:#"token"] initialPresence:nil errorHandler:^(NSString *errorMessage)
{
[self showError:errorMessage];
}];
For reference, I have used this : Respoke Documentation
Please tell me what is missing in my end. Please help me out.
Thanks a lot in advance!
It seems most likely you are having one of these problems:
The value returned by [[aryResult
valueForKey:#"data"]valueForKey:#"token"] is not exactly the same
as the value returned by the Respoke server when asking for a
brokered authentication token from
https://api.respoke.io/v1/tokens due to URL encoding of the data
between the server and your iOS application or something similar.
The brokered authentication token is only valid for 20 seconds, so
perhaps too much time has passed before your iOS application
attempts to use it.
You have not switched your application out of
development mode on the Respoke developer portal, or have not
created a role to use when authenticating. This documentation
page
explains how to properly set up your application and define a role
for using brokered authentication. You can also use the example code
on that page to make sure that you are getting a valid token for
your application. This would help make sure you have your account
configured correctly.
I have resolved the issue by adding some lines of code. Now for the production mode, code will be this:
if (!sharedRespokeClient)
{
// Create a Respoke client instance to be used for the duration of the application
sharedRespokeClient = [[Respoke sharedInstance] createClient];
}
sharedRespokeClient.delegate = self;
[sharedRespokeClient connectWithTokenID:tokenStringFromServer initialPresence:nil errorHandler:^(NSString *errorMessage) {
[self showError:errorMessage];
}];
I am using the Quickblox iOS SDK 2.0.12
I have been following the instructions on Quickblox Authentication and Authorization here.
I call QBRequest createSessionWithSuccessBlock:, and then call QBRequest signUp: inside it's completion block, and then I call QBRequest logInWithUserLogin: inside the next completion block.
According to the above link, I should now have a Quickblox User Session after doing all of this. This all works perfectly and all of the calls are successful and I can see that the user is now in the Quickblox Admin Panel.
After doing this, if I make Quickblox requests they work fine. The only weird thing is that [[QBSession currentSession] currentUser] NSLogs as (null).
Anyways, if I stop running the app on the simulator, and then run the app again 10 minutes later, I check for persisted custom data so I can see if the user has already signed up or not. When the user has signed up, then I take them into the app instead of them needing to signup or login again.
Now, if I try to make any requests to Quickblox, I get the following exception:
Terminating app due to uncaught exception 'BaseServiceException', reason: 'You have missed the authorization call.
Please insert following code inside your application
[QBRequest createSessionWithSuccessBlock:errorBlock:];
Before any other code, that uses our service, but after setup credentials. Thank you.'
I don't understand why it's saying I need to create a session when I already just created one when the user first signed up. I understand that the session expires every 2 hours, but I am testing this very quickly and I am always receiving this error.
If I NSLog [QBSession currentSession] I can see that there is currently a QBSession object, but if I try to NSLog any of it's properties like sessionDetails, sessionExpirationDate, or currentUser they all log as (null).
As I know, only if you use this method - (void)startSessionForUser:(QBUUser *)user withDetails:(QBASession *)session expirationDate:(NSDate *)sessionDate , you can use this property correct. But I didn't ever use it.
For recreating a session I use [QBConnection setAutoCreateSessionEnabled:YES] and for chat I keep QBUUser in my Manager, and after entering foreground I check XMPP connection [[QBChat instance] isLoggedIn]. Maybee it may help you.
I'm successfully posting to Facebook from our Unity iOS game by initializing at game launch then posting message by first checking the session validity and triggering the login if needed.
At first call, I authorize the game from the Facebook app.
Trying to start the process again, I go to the Facebook app prefs and delete the app authorization.
Now when I try to post again from the game, the post message completion handler has no errors but the post does not appear on the user's wall.
What is the process to correct this? Is there a way to check that the game is authorized before posting, and ask for a new authorization if it's not?
Or is the user decision final and they need to reinstall the app to reset everything?
Even though I'm using Prime31's Facebook plugin for Unity, I'm interested in an iOS SDK answer to this question.
Thank you!
You will get an exception, that you need to handle.
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error{
NSLog(#"didFailWithError : %#",[error description]);
NSDictionary* userinfo=[error userInfo];
NSString *type=[[userinfo valueForKey:#"error"]valueForKey:#"type"];
if([type isEqualToString:#"OAuthException"]){
NSLog(#"Exception from oauth let's take new token");
[facebook authorize:_permissions delegate:self];
}
}
Use this delegate function to handle exception.