Esempio n. 1
0
        internal FirebasePriority(JValue priority)
        {
            if (priority == null || priority.Type == JTokenType.Null)
            {
                Type = PriorityType.None;
                return;
            }

            switch (priority.Type)
            {
                case JTokenType.None:
                    Type = PriorityType.None;
                    return;
                case JTokenType.Integer:
                case JTokenType.Float:
                    Type = PriorityType.Numeric;
                    _fp = priority.Value<float>();
                    return;
                case JTokenType.String:
                    int value;
                    if (int.TryParse(priority.Value<string>(), out value))
                    {
                        Type = PriorityType.Numeric;
                        _fp = value;
                    }
                    else
                    {
                        Type = PriorityType.String;
                        _sp = priority.Value<string>();
                    }
                    return;
                default:
                    throw new Exception(string.Format("Unable to load priority of type: {0}", priority.Type));
            }
        }
Esempio n. 2
0
        public void RefreshAccessToken()
        {
            var p = new Dictionary<string, string> ();

            p.Add ("client_id", chromeSettings.ClientId);
            p.Add ("client_secret", chromeSettings.ClientSecret);
            p.Add ("refresh_token", chromeSettings.RefreshToken);
            p.Add("grant_type", "refresh_token");

            var response = http.PostAsync (chromeSettings.AuthUrl, new FormUrlEncodedContent (p)).Result;

            var result = response.Content.ReadAsStringAsync ().Result;

            var json = JObject.Parse(result);

            this.AccessToken = json["access_token"].ToString();

            JToken expiresJson = new JValue(3400);
            json.TryGetValue("expires_in", out expiresJson);

            this.Expires = DateTime.UtcNow.AddSeconds(expiresJson.Value<int>());

            http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", this.AccessToken);
        }
 private static void EncryptJsonValue(JsonPasswordCrypto cryptoHandler, JValue valueToEncrypt)
 {
     var value = valueToEncrypt.Value<string>();
     var encryptedValue = cryptoHandler.Encrypt(value);
     valueToEncrypt.Replace(JObject.FromObject(encryptedValue));
 }