quickblox auto relogin after disconnection - quickblox

I would like to have my QBchat automatically be logged back in if it is disconnected. When I attempt to send a message and I am logged out, is their a callback function that I can implement to test if I am logged out? Also, if I am correct we must have a session establish with QB, than we log into our QBUUSER, than we must log into our QBChat to send messages? How can reconnect all of these pieces if I lose connection.

In case of logout this method will be called
- (void)chatDidFailWithError:(int)code;
where code will be 0

ChatDidFailWithError is a QBChat delegate method and checks for an active chat instance. If the chat has indeed failed auto-login with the user credentials saved in the DataManager singleton. (Example of which is in the QuickBlox framework's documentation)
(void)chatDidFailWithError:(NSInteger)code {
// recall user credentials from singleton class DataManager
[[QBChat instance] loginWithUser:[DataManager shared].currentUser];
}

Related

How to display user a message on session timeout

I'm implementing an adapter base authentication and trying the session timeout functionality I have updated "worklight.properties"and session timeout is working.
So whenever there is session time out or user clicks logout the logout function is called in CustomLoginModule. This works as expected but is there any way I can find in this logout methods why this method was invoked I mean user clicked logout vs session time out. And also how can I pass this info to the client side.
We have a requirement to display user message on session time out.
MobileFirst 7.1
There is no method provided by IBM MobileFirst to differentiate between a logout made by a user action (clicking "logout") to a logout that happened due to a timeout. This is custom functionality you will need to implement on your own.
If you a user clicks on "logout", store this action as a boolean flag and display the appropriate action.
Based on the value of the flag, you can then decide what message to display in case of a session timeout.

IBM Worklight 6.1.0.1, trouble with 2 adapters based authentication

I am facing to a trouble with 2 adapters based authentication. My app is agenda (hybrid app). All adapter's functions must be protected by security.
my app uses adapters based authentication, like written in samples on DeveloperWorks.
My first adapter (loginAdapter) is dedicated for login (beginning of the mobile app). I developed a handler (handlerLogin, mobile side) with methods isCustomResponse, handlechallenge, etc.. This adapter works.
This adapter allows to get a userId from login and password.
As soon as connected, the user can download his agenda. The mobile calls an other adapter based auth (calendarAdapter). I have an other handler (handlerCalendar) with methods (isCustomResponse, handlechallenge).
When the mobile calls the method getCalendarData (protected method, CalendarAdapter), the server detects that the user is not registered for this adapter, that is why the server send an error (structure authrequired + errorMessage) via the function onAuthRequired.
At this step, all works fine.
Actually, the trouble comes from, that, the first handler (handlerLogin) catches this error, whereas it schould be the second handler (handlerCalendar).
Given that it is catched by the handlerLogin, isCustomResponse and handlechallenge are called, and I do not have the expected result ! I do not know why.
Why it is not catched by the handlerCalendar ?
I verified my code, variable's names, files, etc.. All things are ok.
For informations, I first declared the handlerLogin before the CalendarLogin.
Do you have any ideas, suggestions ??
Thank you in advance
It looks like you used the same realm.
The isCustomResponse function job is to find out if this challenge-handler should take care of this specific request. If you use the same realm for both adapters then the 2 challenge-handlers will react to it.

Extra authentication criteria

I'm trying to implement an extra authentication layer with the purpose of authenticating the user only if he has a certain status.
If the status is different, I want to show a custom login error (Your account has been suspended) and not authenticate the user at all, similar to what happens if the credentials are wrong, but with a different error message.
So far I've tried two options:
I've added a check within a listener that checks for an "InteractiveLoginEvent". Here I can check the user status and set a flash error message but I don't see what's the proper way to redirect back to the login page, since this event has no response method, other than using a header() call which I definitely want to avoid.
I implemented a custom voter, set the "access_decision_manager" startegy to "unanimous" and returned "ACCESS_DENIED" if the status is not allowing the user to authenticate. So far so good, the user cannot access the resources but I see he still gets authenticated. And I definitely don't want that.
I'm not for sure if I'm missing something or if I'm going in the wrong direction.
Since symfony 2 makes a clear difference between authentication and authorization seems that option 2) is related to authorization, so option 1) is more suitable.
So among the "InteractiveLoginEvent" listener I just added the proper check for the user status and by throwing the following exception I managed to implement my functionality as needed:
throw new AuthenticationException('suspend error message');
So the listener looks something like this:
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
{
if ($this->securityContext->isGranted('ROLE_CUSTOMROLE')) {
$user = $this->securityContext->getToken()->getUser();
// ... check for the user status here
throw new AuthenticationException('Your account has been suspended!');
}
}

Using AFIncrementalStore with a WebSockets Application

I'm attempting to adopt AFIncrementalStore for a Mac app that talks to App.Net. Unlike the example applications that come with the framework, I'm using the streaming APIs, with a websocket connection. For this I was using SocketRocket. These parts are working fine: I'm able to set up a request connection to ADN and get a connection ID back. It's this connection ID I supply to the later requests to ADN APIs.
My problem is that the Core Data stack is initialized and firing before I get my first connection ID back from ADN. I'm not sure how to handle this situation.
Currently, I have this code in my app delegate:
self.socketConnection = [[MUNConnectionManager alloc] init];
self.socketConnection.delegate = self;
My connection manager implements a delegate that calls back to the app delegate when the connection ID has been received:
# pragma mark MUNConnectionManager delegate method
- (void)didReceiveConnectionId:(NSString*)connectionId
{
self.connectionId = connectionId;
}
So once this connection ID is received, that's when I'd like to boot AFIncrementalStore into action. But this is perhaps a full second or so after launch, and my AFIncrementalStore client is already crapping out because it doesn't have that connection ID.
Any suggestions appreciated!
I think I may have found the answer to this. In my XIB I have an array controller with the "prepares content" checkbox on. That would have triggered the data store and loaded up all the Core Data stack. When I uncheck that box it doesn't load, and my ADN delegate is free to pull the ID.
So if anyone else runs into this, the answer is the CD stack doesn't load until you try to hit it.

Not getting a delegation callback from MGTwitterEngine

I am trying to get the sentDirectMessages of a twitter user via MGTwitterEngine. However, I am not receiving an MGTwitterEngine delegation method callback from the engine to say its received data.
I put an NSLog to see if the connectionFinished method was being called, and it was, but no other methods were i.e - (void)directMessagesReceived:(NSArray *)messages forRequest:(NSString *)connectionIdentifier
Please could you tell me what the problem is, all delegates are set to self.
[manager.engine getSentDirectMessagesSinceID:0 startingAtPage:0];
Sry, but I will ask the routine question: Do you have MGTwitterEngineDelegate in your .h file?
I suggest throwing some logging in requestSucceeded: and requestFailed:withError:
Are you successfully doing any other types of Twitter communication within that project? within the same class?
EDIT
I setup a DM request and it worked correctly with a requestSucceeded: and a directMessagesReceived:forRequest:
Based on your:
"So everytime I want to get the dm's
of the user, I will have to get the
user to logout and then login again."
I am wondering if this is not an issue where the users token is not being stored correctly? I suggest look into how the successful login is storing the token?
In particular this MGTwitterEngineDelegate method.
- (void)accessTokenReceived:(OAToken *)aToken forRequest:(NSString *)connectionIdentifier
{
NSLog(#"Access token received! %#",aToken);
[manager.engine setAccessToken:aToken];
//I have an OAToken variable called "token" defined in my .h
token = [aToken retain];
NSLog(#"storing token in userdefaults");
//this line is key for maintaining a login token throughout the app
//even when the user closes the app and comes back
[token storeInUserDefaultsWithServiceProviderName:[[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleDisplayName"] prefix:#"twitter"];
//call your dm or whatever methods for after login here
.
.
.
}
Hope this helps.