public static IRequest FromHttpRequest(HttpRequest r)
 {
     var req = new Request()
     {
         Method = new HttpMethod(r.HttpMethod),
         Path = r.RawUrl
     };
     foreach (var h in r.Headers.AllKeys)
     {
         var headerVal = r.Headers[h];
         req.Headers.Add(h.ToLowerInvariant(), headerVal);
     }
     return req;
 }
예제 #2
0
        public void ApplySignatureToIRequest()
        {
            var signer = new HttpSigner(new AuthorizationParser(), new HttpSignatureStringExtractor());

            var request = new Request();
            request.Path = "/hello-world";
            request.Method = HttpMethod.Post;
            request.SetHeader("host", "example.com");
            request.SetHeader("date", DateTime.UtcNow.ToString("r"));

            var spec = new SignatureSpecification()
            {
                Algorithm = "hmac-sha256",
                Headers = new string[] {"host", "(request-target)"},
                KeyId = Fixture.KeyId
            };
            signer.Sign(request, spec, Fixture.KeyId, Fixture.KeyBase64);
            var keyStore = new KeyStore(new Dictionary<string, string>()
            {
                {Fixture.KeyId, Fixture.KeyBase64}
            });
            var signature = signer.Signature(request, spec, keyStore);
            Assert.True(signature.Valid);
        }