public async Task <bool> authenticateUserAsync(string username, string password) { ApiResponse <object> resp = null; try { resp = await authApiInstance.AuthenticateUserAsyncWithHttpInfo(username, password); } catch (ApiException ex) { Debug.WriteLine(ex); var content = ex.ErrorContent; string errorStr = content.ToString(); if (errorStr.Equals(CONN_REFUSED_ERR)) { throw new Exception("Connection to CDB server was refused"); } return(false); } var headers = resp.Headers; if (headers.ContainsKey(TOKEN_KEY)) { var token = headers[TOKEN_KEY]; applyAuthToken(token); if ((bool)await verifyUserAuthenticated()) { mobileAppStorage.addActiveAuthToken(token, username); return(true); } } return(false); }