예제 #1
0
        private static IRestRequest SignWithSTSKeysAndSecurityToken(IRestRequest restRequest, string host, string roleARN, string accessKey, string secretKey)
        {
            AssumeRoleResponse response = null;

            using (var STSClient = new AmazonSecurityTokenServiceClient(accessKey, secretKey, RegionEndpoint.EUWest1))
            {
                var req = new AssumeRoleRequest()
                {
                    RoleArn         = roleARN,
                    DurationSeconds = 950, //put anything you want here
                    RoleSessionName = Guid.NewGuid().ToString()
                };

                response = STSClient.AssumeRoleAsync(req, new CancellationToken()).Result;
            }

            //auth step 3: dönen değerler bizim yeni tokenlarımızı...
            var awsAuthenticationCredentials = new AWSAuthenticationCredentials
            {
                AccessKeyId = response.Credentials.AccessKeyId,
                SecretKey   = response.Credentials.SecretAccessKey,
                Region      = REGION
            };

            restRequest.AddHeader("x-amz-security-token", response.Credentials.SessionToken);
            return(new AWSSigV4Signer(awsAuthenticationCredentials).Sign(restRequest, host));
        }
예제 #2
0
        public IRestRequest SignRequest(IRestRequest restRequest, RestClient restClient, string contentType)
        {
            // Seller APIs
            LWAAuthorizationCredentials lwaAuthorizationCredentials = new LWAAuthorizationCredentials
            {
                ClientId     = ClientId,
                ClientSecret = ClientSecret,
                RefreshToken = RefreshToken,
                Endpoint     = Endpoint
            };
            AWSAuthenticationCredentials awsAuthenticationCredentials = new AWSAuthenticationCredentials
            {
                AccessKeyId = AccessKeyId,
                SecretKey   = SecretKey,
                Region      = Region
            };

            restRequest = new AWSSigV4Signer(awsAuthenticationCredentials)
                          .Sign(restRequest, restClient.BaseUrl.Host);

            restRequest.AddHeader("Content-type", contentType);

            restRequest.AddHeader("user-agent", "My YouTube App 1.0 (Language=csharp;Platform=Windows/10)");

            return(restRequest);
        }
예제 #3
0
        public AWSSigV4SignerTest()
        {
            request = new HttpRequestMessage(HttpMethod.Get, TestUri);

            AWSAuthenticationCredentials authenticationCredentials = new AWSAuthenticationCredentials
            {
                AccessKeyId = TestAccessKeyId,
                SecretKey   = TestSecretKey,
                Region      = TestRegion
            };

            mockAWSSignerHelper  = new Mock <AWSSignerHelper>();
            sigV4SignerUnderTest = new AWSSigV4Signer(authenticationCredentials);
            sigV4SignerUnderTest.AwsSignerHelper = mockAWSSignerHelper.Object;
        }
        public AWSSigV4SignerTest()
        {
            request = new RestRequest(TestResourcePath, Method.GET);

            AWSAuthenticationCredentials authenticationCredentials = new AWSAuthenticationCredentials
            {
                AccessKeyId = TestAccessKeyId,
                SecretKey   = TestSecretKey,
                Region      = TestRegion
            };

            mockAWSSignerHelper  = new Mock <AWSSignerHelper>();
            sigV4SignerUnderTest = new AWSSigV4Signer(authenticationCredentials);
            sigV4SignerUnderTest.AwsSignerHelper = mockAWSSignerHelper.Object;
        }