fredriksthlm is correct. You are not calling the interface correctly. All of those calls are asynchronous, which means you have to wait for the trigger to occur before proceeding. If it worked before, then you just got lucky, but given that you have a second authenticate 'in case the first one fails' implies that you have had issues before, and 'fixed' it with a second call. That's not the fix.
You may need to alter your code to block events while the async calls run.