Пример #1
0
        public void CreateSignature_EmptyTokenSecretTest()
        {
            // GET http://example.com/hoge?aaa=foo に対する署名を生成
            // リクエストトークンの発行時は tokenSecret が空の状態で署名を生成することになる
            var oauthSignature = OAuthUtility.CreateSignature("ConsumerSecret", null,
                                                              "GET", new Uri("http://example.com/hoge"), new Dictionary <string, string> {
                ["aaa"] = "foo"
            });

            var expectSignatureBase = "GET&http%3A%2F%2Fexample.com%2Fhoge&aaa%3Dfoo";
            var expectSignatureKey  = "ConsumerSecret&"; // 末尾の & は除去されない

            using var hmacsha1 = new HMACSHA1(Encoding.ASCII.GetBytes(expectSignatureKey));
            var expectSignature = Convert.ToBase64String(hmacsha1.ComputeHash(Encoding.ASCII.GetBytes(expectSignatureBase)));

            Assert.Equal(expectSignature, oauthSignature);
        }
Пример #2
0
        public void CreateSignature_Test()
        {
            // GET http://example.com/hoge?aaa=foo に対する署名を生成
            // 実際の param は oauth_consumer_key などのパラメーターが加わった状態で渡される
            var oauthSignature = OAuthUtility.CreateSignature("ConsumerSecret", "TokenSecret",
                                                              "GET", new Uri("http://example.com/hoge"), new Dictionary <string, string> {
                ["aaa"] = "foo"
            });

            var expectSignatureBase = "GET&http%3A%2F%2Fexample.com%2Fhoge&aaa%3Dfoo";
            var expectSignatureKey  = "ConsumerSecret&TokenSecret";

            using var hmacsha1 = new HMACSHA1(Encoding.ASCII.GetBytes(expectSignatureKey));
            var expectSignature = Convert.ToBase64String(hmacsha1.ComputeHash(Encoding.ASCII.GetBytes(expectSignatureBase)));

            Assert.Equal(expectSignature, oauthSignature);
        }
Пример #3
0
        public void CreateSignature_NormarizeParametersTest()
        {
            // GET http://example.com/hoge?aaa=foo&bbb=bar に対する署名を生成
            // 複数のパラメータが渡される場合は name 順でソートされる
            var oauthSignature = OAuthUtility.CreateSignature("ConsumerSecret", "TokenSecret",
                                                              "GET", new Uri("http://example.com/hoge"), new Dictionary <string, string> {
                ["bbb"] = "bar",
                ["aaa"] = "foo",
            });

            var expectSignatureBase = "GET&http%3A%2F%2Fexample.com%2Fhoge&aaa%3Dfoo%26bbb%3Dbar";
            var expectSignatureKey  = "ConsumerSecret&TokenSecret";

            using var hmacsha1 = new HMACSHA1(Encoding.ASCII.GetBytes(expectSignatureKey));
            var expectSignature = Convert.ToBase64String(hmacsha1.ComputeHash(Encoding.ASCII.GetBytes(expectSignatureBase)));

            Assert.Equal(expectSignature, oauthSignature);
        }