static void ParseAuthorizationHeader(NameValueCollection headers, OAuthContext context)
 {
     if (headers.AllKeys.Contains("Authorization"))
     {
         context.AuthorizationHeaderParameters = UriUtility.GetHeaderParameters(headers["Authorization"]).ToNameValueCollection();
         context.UseAuthorizationHeader        = true;
     }
 }
        public IOAuthContext FromHttpRequest(HttpRequestBase request)
        {
            var context = new OAuthContext
            {
                RawUri                = CleanUri(request.Url),
                Cookies               = CollectCookies(request),
                Headers               = new NameValueCollection(request.Headers),
                RequestMethod         = request.HttpMethod,
                FormEncodedParameters = new NameValueCollection(request.Form),
                QueryParameters       = new NameValueCollection(request.QueryString),
            };

            if (request.Headers.AllKeys.Contains("Authorization"))
            {
                context.AuthorizationHeaderParameters = UriUtility.GetHeaderParameters(request.Headers["Authorization"]).ToNameValueCollection();
                context.UseAuthorizationHeader        = true;
            }

            return(context);
        }
        public IOAuthContext FromMessage(Message request)
        {
            var requestProperty = (HttpRequestMessageProperty)request.Properties[HttpRequestMessageProperty.Name];
            var context         = new OAuthContext
            {
                RawUri          = CleanUri(request.Headers.To),
                Headers         = new NameValueCollection(requestProperty.Headers),
                RequestMethod   = requestProperty.Method,
                QueryParameters = HttpUtility.ParseQueryString(requestProperty.QueryString),
            };

            string authHeader = requestProperty.Headers["Authorization"];

            if (!string.IsNullOrEmpty(authHeader))
            {
                context.AuthorizationHeaderParameters = UriUtility.GetHeaderParameters(authHeader).ToNameValueCollection();
                context.UseAuthorizationHeader        = true;
            }

            return(context);
        }