Exemplo n.º 1
0
        private IPlatformUser AuthenticateWithDeviceToken()
        {
            if (!string.IsNullOrEmpty(User.DeviceToken))
            {
                try
                {
                    var client = new RestClient(Host.Url);
                    client.AddCookie(new Cookie("device_credentials", User.DeviceToken));
                    client.AddParameter("includes", "a.profile");
                    var response = client.Get("/api/v1.3/current_user.json");
                    if (response.IsSuccessStatusCode)
                    {
                        Session.Cookies = client.CookieContainer;
                        User.IsDeactivated = client.Content.SelectToken("is_deactivated").Value<bool>();
                        User.AccountId = client.Content.SelectToken("account").SelectToken("id").Value<string>();
                        User.Uuid = client.Content.SelectToken("uuid").Value<string>();
                        User.Email = client.Content.SelectToken("email").Value<string>();
                        User.Account = new PlatformAccount(Session, client.Content.SelectToken("account"));

                        if (User.IsDeactivated)
                            throw new UnauthorizedAccessException("The account has been deactivated.");


                        return User;
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError(e);
                }

            }
            return null;
        }