Ejemplo n.º 1
0
        private AccessToken GetAccessToken(AccessToken token)
        {
            AccessToken Token = new AccessToken();

            Synergy.Common.Request.WebClient client = new Synergy.Common.Request.WebClient();
            HttpWebResponse response = client.Post(new JsonMessage(null, GetRefreshTokenUrl(token.RefreshToken)), GetAuthenticationToken(), EnumUtilities.GetDescriptionFromEnumValue(ContentTypes.JSON));

            if (response != null && response.StatusCode == HttpStatusCode.OK)
            {
                var          responseStream = response.GetResponseStream();
                StreamReader streamReader   = new StreamReader(responseStream);
                string       rawResponse    = streamReader.ReadToEnd();
                Token        = JsonConvert.DeserializeObject <AccessToken>(rawResponse);
                _AccessToken = Token;
            }
            return(Token);
        }
Ejemplo n.º 2
0
        private AccessToken GetAccessToken(string code, string redirectUri)
        {
            AccessToken Token = new AccessToken();

            Synergy.Common.Request.WebClient client = new Synergy.Common.Request.WebClient();
            var             Content  = string.Format("client_id={0}&client_secret={1}&code={2}&grant_type={3}&redirect_uri={4}", InfusionKey, InfusionSecret, code, GrantType, redirectUri);
            HttpWebResponse response = client.Post(new JsonMessage(Encoding.UTF8.GetBytes(Content), GetAccessTokenUrl()), null, EnumUtilities.GetDescriptionFromEnumValue(ContentTypes.URLENCODED));

            if (response != null && response.StatusCode == HttpStatusCode.OK)
            {
                var          responseStream = response.GetResponseStream();
                StreamReader streamReader   = new StreamReader(responseStream);
                string       rawResponse    = streamReader.ReadToEnd();
                Token        = JsonConvert.DeserializeObject <AccessToken>(rawResponse);
                _AccessToken = Token;
            }
            return(Token);
        }