Esempio n. 1
0
        private async Task <bool> refreshToken()
        {
            try
            {
                var stringPayload            = JsonConvert.SerializeObject(currentUser);
                var httpContent              = new StringContent(stringPayload, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await httpClient.PostAsync(Models.DejamobileApiModel.backendBaseUrl + Models.DejamobileApiModel.login, httpContent);

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    string json = await getJsonFromHttpResponse(response);

                    Models.AuthJwtModel authJwt = JsonConvert.DeserializeObject <Models.AuthJwtModel>(json);
                    storeAuthJwt(currentUser, authJwt.token);
                    Console.WriteLine("Token has been refreshed !");
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception while trying to refreshtoken : " + e.Message);
                return(false);
            }
        }
Esempio n. 2
0
        public async Task <TaskResult> ConnectUser(Models.UserModel user)
        {
            HttpResponseMessage rsp = await customHttpClient.performRequest(DejaMobileHttpClient.Request.logUser, user);

            if (rsp.StatusCode == System.Net.HttpStatusCode.OK)
            {
                string json = await DejaMobileHttpClient.getJsonFromHttpResponse(rsp);

                Models.AuthJwtModel authJwt = JsonConvert.DeserializeObject <Models.AuthJwtModel>(json);
                onUserConnected(user, authJwt.token);
                return(new TaskResult(TaskResult.TaskName.logUser, true, TaskResult.TaskStatus.finished, null, "User successfully connected"));
            }
            else
            {
                onUserNotConnected();
                return(new TaskResult(TaskResult.TaskName.logUser, false, TaskResult.TaskStatus.finished, null, "ERROR while connecting user : " + rsp.StatusCode.ToString()));
            }
        }