Beispiel #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();
            }
        }
Beispiel #2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="request"></param>
 /// <param name="message"></param>
 public static void WriteRequest(this HttpWebRequest request, ResourceRequest message)
 {
     request.Headers["Authorization"] = "WRAP access_token=\"" + message.AccessToken + "\"";
 }
Beispiel #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="request"></param>
 /// <param name="message"></param>
 public static void WriteRequest(this WebRequest request, ResourceRequest message)
 {
     var httpRequest = request as HttpWebRequest;
     if (null == httpRequest)
         throw new NotSupportedException("Only HttpWebRequests are supported.");
     httpRequest.WriteRequest(message);
 }