Ejemplo n.º 1
0
        /// <summary>
        /// Authorizes the specified code.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="appId">The application identifier.</param>
        /// <param name="appSecret">The application secret.</param>
        /// <returns></returns>
        public AuthResult Authorize(string code, string appId, string appSecret)
        {
            string url = Config.ACCESS_TOKEN_ENDPOINT;

            NameValueCollection parameter = new NameValueCollection();

            parameter.Add("app_id", appId);
            parameter.Add("app_secret", appSecret);
            parameter.Add("code", code);

            url = url + "?" + parameter.ToQueryString();

            string postData = string.Empty;
            string data     = this.Post(url, Config.CONTENT_TYPE_FORM, postData);

            var result = new AuthResult();

            this.AccessToken      = string.Empty;
            this.SubscriberNumber = string.Empty;

            if (data.Contains(Config.ERROR))
            {
                var jsonResponse = JsonConvert.DeserializeObject <ErrorResponse>(data);
                result.Result = null;
                result.Status = this.ResponseStatus;
                result.Status.StatusDescription = jsonResponse.Error;
                result.Status.StatusCode        = (int)HttpStatusCode.BadRequest;
            }
            else
            {
                var jsonResponse = JsonConvert.DeserializeObject <AuthResponse>(data);
                result.Result = jsonResponse;
                result.Status = this.ResponseStatus;

                this.AccessToken      = jsonResponse.AccessToken;
                this.SubscriberNumber = jsonResponse.SubscriberNumber;
            }

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Authorizes the specified code.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="appId">The application identifier.</param>
        /// <param name="appSecret">The application secret.</param>
        /// <returns></returns>
        public AuthResult Authorize(string code, string appId, string appSecret)
        {
            string url = Config.ACCESS_TOKEN_ENDPOINT;

            NameValueCollection parameter = new NameValueCollection();

            parameter.Add("app_id", appId);
            parameter.Add("app_secret", appSecret);
            parameter.Add("code", code);

            url = url + "?" + parameter.ToQueryString();

            string postData = string.Empty;
            string data = this.Post(url, Config.CONTENT_TYPE_FORM, postData);

            var result = new AuthResult();
            this.AccessToken = string.Empty;
            this.SubscriberNumber = string.Empty;

            if (data.Contains(Config.ERROR))
            {
                var jsonResponse = JsonConvert.DeserializeObject<ErrorResponse>(data);
                result.Result = null;
                result.Status = this.ResponseStatus;
                result.Status.StatusDescription = jsonResponse.Error;
                result.Status.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            else
            {
                var jsonResponse = JsonConvert.DeserializeObject<AuthResponse>(data);
                result.Result = jsonResponse;
                result.Status = this.ResponseStatus;

                this.AccessToken = jsonResponse.AccessToken;
                this.SubscriberNumber = jsonResponse.SubscriberNumber;
            }

            return result;
        }