コード例 #1
0
        public static void SignRequest(IRequest request, byte[] body, AwsCredentials credentials, string region, string service)
        {
            var date      = DateTime.UtcNow;
            var dateStamp = date.ToString("yyyyMMdd");
            var amzDate   = date.ToString("yyyyMMddTHHmmssZ");

            request.Headers.XAmzDate = amzDate;

            var signingKey   = GetSigningKey(credentials.SecretKey, dateStamp, region, service);
            var stringToSign = GetStringToSign(request, body, region, service);

            Debug.Write("========== String to Sign ==========\r\n{0}\r\n========== String to Sign ==========\r\n", stringToSign);
            var signature = signingKey.GetHmacSha256Hash(stringToSign).ToLowercaseHex();
            var auth      = string.Format(
                "AWS4-HMAC-SHA256 Credential={0}/{1}, SignedHeaders={2}, Signature={3}",
                credentials.AccessKey,
                GetCredentialScope(dateStamp, region, service),
                GetSignedHeaders(request),
                signature);

            request.Headers.Authorization = auth;
            if (!String.IsNullOrWhiteSpace(credentials.Token))
            {
                request.Headers.XAmzSecurityToken = credentials.Token;
            }
        }
コード例 #2
0
 public StaticCredentialsProvider(AwsCredentials credentials)
 {
     if (credentials == null)
     {
         throw new ArgumentNullException(nameof(credentials));
     }
     if (string.IsNullOrEmpty(credentials.AccessKey))
     {
         throw new ArgumentException("AccessKey is required.", nameof(credentials));
     }
     if (string.IsNullOrEmpty(credentials.SecretKey))
     {
         throw new ArgumentException("SecretKey is required.", nameof(credentials));
     }
     _credentials = credentials;
 }
コード例 #3
0
        public AwsCredentials GetCredentials()
        {
            var chain    = new CredentialProfileStoreChain();
            var profiles = chain.ListProfiles();
            CredentialProfile profile = profiles.FirstOrDefault();

            if (profile == null)
            {
                return(null);
            }

            var credentials = profile.GetAWSCredentials(chain).GetCredentials();
            var credential  = new AwsCredentials {
                AccessKey = credentials.AccessKey, SecretKey = credentials.SecretKey, Token = credentials.Token
            };

            return(new AwsCredentials
            {
                AccessKey = credential.AccessKey,
                SecretKey = credential.SecretKey,
                Token = credential.Token
            });
        }