Akamai.EdgeGrid.Auth.EdgeGridV1Signer.GetAuthorizationHeaderValue C# (CSharp) Метод

GetAuthorizationHeaderValue() приватный Метод

private GetAuthorizationHeaderValue ( ClientCredential credential, System.DateTime timestamp, string authData, string requestData ) : string
credential ClientCredential
timestamp System.DateTime
authData string
requestData string
Результат string
        internal string GetAuthorizationHeaderValue(ClientCredential credential, DateTime timestamp, string authData, string requestData)
        {
            string signingKey = timestamp.ToISO8601().ToByteArray().ComputeKeyedHash(credential.Secret, this.SignVersion.Algorithm).ToBase64();
            string authSignature = string.Format("{0}{1}", requestData, authData).ToByteArray().ComputeKeyedHash(signingKey, this.SignVersion.Algorithm).ToBase64();
            return string.Format("{0}signature={1}", authData, authSignature);
        }

Usage Example

        public void GetAuthorizationHeaderValueTest()
        {
            string   clientToken = "akaa-275ca6de04b11b91-cf46074bf3b52950";
            string   accessToken = "akaa-d6cfbdb2d0594ae4-ad000cf3a5473a08";
            string   secret      = "secret-shh";
            DateTime timestamp   = new DateTime(1918, 11, 11, 11, 00, 00, DateTimeKind.Utc);

            EdgeGridV1Signer signer     = new EdgeGridV1Signer();
            ClientCredential credential = new ClientCredential(clientToken, accessToken, secret);

            Assert.AreEqual("auth-datasignature=c5ZV4+bUosZjISLUvr6kakI3djQoLo6CaAD0IaVbNDg=", signer.GetAuthorizationHeaderValue(credential, timestamp, "auth-data", null));
            Assert.AreEqual("auth-datasignature=LNWyXpxHlp4GYfD+biysQmSCZPmoucvWze2p/beX4O8=", signer.GetAuthorizationHeaderValue(credential, timestamp, "auth-data", "body-data"));

            //putting it all together
            string authData = "Authorization: EG1-HMAC-SHA256 client_token=akaa-275ca6de04b11b91-cf46074bf3b52950;access_token=akaa-d6cfbdb2d0594ae4-ad000cf3a5473a08;timestamp=19181111T11:00:00Z;nonce=dd9957e2-4fe5-48ca-8d32-16a772ac6d8f;";
            string authBody = "GET\thttp\twww.example.com\t/\t\t\t";

            Assert.AreEqual(string.Format("{0}signature=0iSbrT0ze1uDfJdodKOevZSSjYkXllt6VlLSghOiWtY=", authData), signer.GetAuthorizationHeaderValue(credential, timestamp, authData, authBody));
            //Assert.Catch<ArgumentNullException>(delegate { signer.GetAuthorizationHeaderValue(credential, null, authData, authBody); });
        }