public virtual Dictionary <string, string> ReadFormEncodedParameters(System.IO.Stream incomingStream)
 {
     if (incomingStream == null)
     {
         throw new ArgumentNullException("incomingStream");
     }
     System.IO.StreamReader reader = new System.IO.StreamReader(incomingStream);
     return(HttpQueryStringParser.Parse(reader.ReadToEnd()));
 }
Exemplo n.º 2
0
        private DateTime _expirationDate; // Token's expiration date.

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="resourcePath">Path of the authenticated resource.</param>
        /// <param name="response">HTTP response with the token.</param>
        internal WrapToken(string resourcePath, HttpResponseMessage response)
        {
            Debug.Assert(response.IsSuccessStatusCode);
            Scope = resourcePath;
            string content = response.Content.ReadAsStringAsync().Result;
            HttpQueryStringParser query = new HttpQueryStringParser(content);

            Token = string.Format(CultureInfo.InvariantCulture, Constants.WrapTokenAuthenticationString, WebUtility.UrlDecode(query["wrap_access_token"]));
            _expirationDate = DateTime.Now + TimeSpan.FromSeconds(int.Parse(query["wrap_access_token_expires_in"]) / 2);
        }
        public virtual OAuthMessage Read(string httpMethod, string httpContentType, Uri requestUri, System.IO.Stream incomingStream)
        {
            if (string.IsNullOrEmpty(httpMethod))
            {
                throw new ArgumentOutOfRangeException("httpMethod");
            }
            if (requestUri == null)
            {
                throw new ArgumentNullException("requestUri");
            }
            if (incomingStream == null)
            {
                throw new ArgumentNullException("incomingStream");
            }

            Dictionary <string, string> oAuthParameters = new Dictionary <string, string>();

            if (httpMethod == "POST")
            {
                if (httpContentType.Contains("application/x-www-form-urlencoded"))
                {
                    oAuthParameters = this.ReadFormEncodedParameters(incomingStream);
                }
                else
                {
                    if (!httpContentType.Contains("application/json"))
                    {
                        throw new OAuthMessageSerializationException(string.Format(Resources.ID3721, httpMethod, httpContentType));
                    }
                    oAuthParameters = this.ReadJsonEncodedParameters(incomingStream);
                }
            }
            else
            {
                if (!(httpMethod == "GET"))
                {
                    throw new OAuthMessageSerializationException(string.Format(Resources.ID3722, httpMethod));
                }
                oAuthParameters = HttpQueryStringParser.Parse(requestUri.Query);
            }
            return(this.CreateTypedOAuthMessageFromParameters(OAuthMessageSerializer.GetBaseUrl(requestUri), oAuthParameters));
        }