Example #1
0
        public void TestSTS(string secretId, string secretKey, string policy)
        {
            string camHost   = "sts.api.qcloud.com";
            string camPath   = "/v2/index.php";
            string camMethod = "GET";
            bool   isHttps   = true;
            Dictionary <string, string> queryParameters = new Dictionary <string, string>();

            queryParameters.Add("policy", policy);
            queryParameters.Add("name", "brady");
            queryParameters.Add("Action", "GetFederationToken");
            queryParameters.Add("SecretId", secretId);
            queryParameters.Add("Nonce", new Random().Next(1, int.MaxValue).ToString());
            long time = TimeUtils.GetCurrentTime(TimeUnit.SECONDS);

            queryParameters.Add("Timestamp", time.ToString());
            queryParameters.Add("RequestClient", "net-sdk-v5");
            queryParameters.Add("durationSeconds", 7200.ToString());
            string plainText = MakeSignPlainText(queryParameters, camMethod, camHost, camPath);
            string hamcSha1  = DigestUtils.GetHamcSha1ToBase64(plainText, Encoding.UTF8, secretKey, Encoding.UTF8);

            queryParameters.Add("Signature", hamcSha1);

            HttpUrl httpUrl = new HttpUrl();

            httpUrl.Scheme = isHttps ? "https" : "http";
            httpUrl.Host   = camHost;
            httpUrl.Path   = camPath;
            Dictionary <string, string> tmp = new Dictionary <string, string>(queryParameters.Count);

            foreach (KeyValuePair <string, string> pair in queryParameters)
            {
                tmp.Add(pair.Key, URLEncodeUtils.Encode(pair.Value).Replace("%20", "+"));
            }
            queryParameters.Clear();
            httpUrl.SetQueryParameters(tmp);

            SetSTSRequest(camMethod, isHttps, httpUrl);
        }