Beispiel #1
0
        public static Authentication.token get_access_token(string code, string client_id, string client_secret, string redirect_uri, string grant_type = "authorization_code")
        {
            json_parameters_get_access_token_by_code json = new json_parameters_get_access_token_by_code();
            json.code = code;
            json.client_id = client_id;
            json.client_secret = client_secret;
            json.redirect_uri = redirect_uri;
            json.grant_type = grant_type;

            string requestUrl = string.Format("{0}/v3/auth/token?ct={1}", Configuration.base_url, System.Web.HttpUtility.UrlEncode(Configuration.user_agent));
            Dictionary<string, string> headers = new Dictionary<string, string>();
            Dictionary<string, string> content = new Dictionary<string,string>();
            content.Add("code", System.Web.HttpUtility.UrlEncode(code));
            content.Add("client_id",client_id);
            content.Add("client_secret", System.Web.HttpUtility.UrlEncode(client_secret));
            content.Add("redirect_uri", redirect_uri);
            content.Add("grant_type",grant_type);

            Common.HTTPCommunications.Response response = Common.HTTPCommunications.SendPostRequest(
                requestUrl,
                content,
                headers,
                true);

            JsonSerializerSettings settings = new JsonSerializerSettings();
            settings.Error += delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
            {
                throw args.ErrorContext.Error;
            };

            return JsonConvert.DeserializeObject<Model.Authentication.token>(response.Content, settings);
        }
Beispiel #2
0
        public static Authentication.token get_access_token(string code, string client_id, string client_secret, string redirect_uri, string grant_type = "authorization_code")
        {
            json_parameters_get_access_token_by_code json = new json_parameters_get_access_token_by_code();

            json.code          = code;
            json.client_id     = client_id;
            json.client_secret = client_secret;
            json.redirect_uri  = redirect_uri;
            json.grant_type    = grant_type;

            string requestUrl = string.Format("{0}/v3/auth/token?ct={1}", Configuration.base_url, System.Web.HttpUtility.UrlEncode(Configuration.user_agent));
            Dictionary <string, string> headers = new Dictionary <string, string>();
            Dictionary <string, string> content = new Dictionary <string, string>();

            content.Add("code", System.Web.HttpUtility.UrlEncode(code));
            content.Add("client_id", client_id);
            content.Add("client_secret", System.Web.HttpUtility.UrlEncode(client_secret));
            content.Add("redirect_uri", redirect_uri);
            content.Add("grant_type", grant_type);


            Common.HTTPCommunications.Response response = Common.HTTPCommunications.SendPostRequest(
                requestUrl,
                content,
                headers,
                true);


            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Error += delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
            {
                throw args.ErrorContext.Error;
            };

            return(JsonConvert.DeserializeObject <Model.Authentication.token>(response.Content, settings));
        }