Ejemplo n.º 1
0
        public void Process(AcceptResponse responseMessage)
        {
            var accessTokenUrl = new Uri("https://wrap.issuer:447/AccessToken.aspx");
            var resourceTokenUrl = new Uri("https://wrap.resource:448/Time.ashx");

            var requestMessage = new WebAppRequest("client name", "client password", responseMessage.VerificationCode, Request.Url.Host);

            // Send the message to the Access Token URL of the Authorization Server
            var request = WebRequest.Create(accessTokenUrl);
            request.WriteRequest(requestMessage);

            // Parse and show result
            var accessResponseMessage = request.GetResponse().ReadAccessTokenResponse();

            // Access resource with token
            request = WebRequest.Create(resourceTokenUrl) as HttpWebRequest;
            // request.Method = "POST";
            // request.ContentLength = 0;
            var resourceRequestMessage = new ResourceRequest(accessResponseMessage.AccessToken);
            request.WriteRequest(resourceRequestMessage);

            using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
            {
                time.InnerText = reader.ReadToEnd();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="names"></param>
        /// <returns></returns>
        public static AuthorizationResponse ReadAuthorizationResponse(this NameValueCollection names)
        {
            if (null == names)
                throw new ArgumentNullException("names");

            AuthorizationResponse message = null;
            if (false == String.IsNullOrEmpty(names[WrapConstants.Parameters.VerificationCode]))
                message = new AcceptResponse();
            else if (false == String.IsNullOrEmpty(names[WrapConstants.Parameters.ErrorReason]))
                message = new RejectResponse();

            foreach (String key in names.Keys)
            {
                String value = names[key];
                if (false == key.StartsWith("wrap_", StringComparison.OrdinalIgnoreCase) || String.IsNullOrEmpty(value))
                    continue;
                message.SetParameter(key, value);
            }
            message.Validate();

            return message;
        }