Example #1
0
        public void StandardInput_ReturnsSignature()
        {
            var subject        = new AmazonMWSV2RequestUrlBuilder();
            var requestOptions = new AmazonMWSClientOptions
            {
                RegionEndpoint = AmazonMWSDefaultEndpoint.NorthAmerica,
                AWSAccessKeyId = "foo",
                SecretKey      = "bar",
            };

            var requestUrl = subject.CreateRequestUri(new Request {
                Resource = "Orders", Version = "2013-09-01", Action = "ListOrders"
            }, requestOptions);

            // Not sure what to test, at least no exception
        }
Example #2
0
        public Uri CreateRequestUri(Request request, AmazonMWSClientOptions options)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var sortedParameters = new SortedDictionary <string, object>(StringComparer.Ordinal);

            if (request.Parameters != null)
            {
                foreach (var parameter in request.Parameters)
                {
                    sortedParameters.Add(parameter.Key, parameter.Value);
                }
            }
            sortedParameters["Action"]          = request.Action ?? throw new ArgumentException("Request is missing an action", nameof(request));
            sortedParameters["SignatureMethod"] = SignatureMethod;
            sortedParameters["Timestamp"]       = DateTime.UtcNow;
            sortedParameters["AWSAccessKeyId"]  = options.AWSAccessKeyId;
            sortedParameters["SellerId"]        = options.SellerId;

            if (!string.IsNullOrEmpty(options.MWSAuthToken))
            {
                sortedParameters["MWSAuthToken"] = options.MWSAuthToken;
            }

            switch (SignatureVersion)
            {
            case SignatureVersion.v1:
                throw new NotSupportedException("V1 signatures are not implemented");

            case SignatureVersion.v2:
                sortedParameters["SignatureVersion"] = "2";
                break;

            default:
                throw new InvalidOperationException("Unsupported signature version");
            }

            var path        = $"/{request.Resource}/{request.Version}";
            var queryString = QueryHelper.BuildCanonicalQueryString(sortedParameters);

            // If Signature Version is 2, string to sign is based on following:
            // 1. The HTTP Request Method followed by an ASCII newline (%0A)
            // 2. The HTTP Host header in the form of lowercase host, followed by an ASCII newline.
            // 3. The URL encoded HTTP absolute path component of the URI (up to but not including the query string parameters); if this is empty use a forward '/'. This parameter is followed by an ASCII newline.
            // 4. The concatenation of all query string components (names and values) as UTF-8 characters which are URL encoded as per RFC 3986 (hex characters MUST be uppercase), sorted using lexicographic byte ordering.
            //    Parameter names are separated from their values by the '=' character (ASCII character 61), even if the value is empty. Pairs of parameter and values are separated by the '&' character (ASCII code 38).
            var signature       = string.Join("\n", "POST", HostFromEndpoint(options.RegionEndpoint).ToLowerInvariant(), path, queryString);
            var hashedSignature = Hash(options.SecretKey, signature);

            queryString += $"&Signature={WebUtility.UrlEncode(hashedSignature)}";
            return(new UriBuilder(options.RegionEndpoint)
            {
                Path = path,
                Query = queryString
            }.Uri);
        }
 public Task <Response <CancelFeedSubmissionsResult> > CancelFeedSubmissions(CancelFeedSubmissionsRequest request, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <CancelFeedSubmissionsResult>(new Request {
     Resource = resourceName, Version = version, Action = "GetFeedSubmissionCount", Parameters = request.ToParametersDictionary(), ClientOptions = clientOptions
 }, cancellationToken);
 public Task <StreamedResponse> GetFeedSubmissionResult(string feedSubmissionId, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute(new Request {
     Resource = resourceName, Version = version, Action = "GetFeedSubmissionResult", Parameters = new ParameterDictionaryBuilder().Add("FeedSubmissionId", feedSubmissionId).Parameters, ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <GetFeedSubmissionListResult> > GetFeedSubmissionListByNextToken(string nextToken, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <GetFeedSubmissionListResult>(new Request {
     Resource = resourceName, Version = version, Action = "GetFeedSubmissionListByNextToken", Parameters = new ParameterDictionaryBuilder().Add("NextToken", nextToken).Parameters, ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <SubmitFeedResult> > SubmitFeed(SubmitFeedRequest request, Stream feedContent, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <SubmitFeedResult>(new Request {
     Resource = resourceName, Version = version, Action = "SubmitFeed", Parameters = request.ToParametersDictionary(), Body = feedContent, ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <UpdateReportAcknowledgementsResult> > UpdateReportAcknowledgements(UpdateReportAcknowledgementsRequest request, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <UpdateReportAcknowledgementsResult>(new Request {
     Resource = resourceName, Version = version, Action = "UpdateReportAcknowledgements", Parameters = request.ToParametersDictionary(), ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <GetReportScheduleCountResult> > GetReportScheduleCount(GetReportScheduleCountRequest request, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <GetReportScheduleCountResult>(new Request {
     Resource = resourceName, Version = version, Action = "GetReportScheduleCount", Parameters = request.ToParametersDictionary(), ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <ListMarketplaceParticipationsResult> > ListMarketplaceParticipationsByNextToken(string nextToken, AmazonMWSClientOptions clientOptions = null, CancellationToken cancellationToken = default)
 => channel.Execute <ListMarketplaceParticipationsResult>(new Request {
     Resource = resourceName, Version = version, Action = nameof(ListMarketplaceParticipationsByNextToken), Parameters = new ParameterDictionaryBuilder().Add("NextToken", nextToken).Parameters, ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <ListMarketplaceParticipationsResult> > ListMarketplaceParticipations(AmazonMWSClientOptions clientOptions = null, CancellationToken cancellationToken = default)
 => channel.Execute <ListMarketplaceParticipationsResult>(new Request {
     Resource = resourceName, Version = version, Action = nameof(ListMarketplaceParticipations), ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <ListOrderItemsResult> > ListOrderItems(string amazonOrderId, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <ListOrderItemsResult>(new Request {
     Resource = resourceName, Version = version, Action = "ListOrderItems", Parameters = new ParameterDictionaryBuilder().Add("AmazonOrderId", amazonOrderId).Parameters, ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <ListOrdersResult> > ListOrders(ListOrdersRequest request, AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <ListOrdersResult>(new Request {
     Resource = resourceName, Version = version, Action = "ListOrders", Parameters = request.ToParametersDictionary(), ClientOptions = clientOptions
 }, cancellationToken);
 public Task <Response <ServiceStatusResult> > GetServiceStatus(AmazonMWSClientOptions clientOptions, CancellationToken cancellationToken)
 => channel.Execute <ServiceStatusResult>(new Request {
     Resource = resourceName, Version = version, Action = "GetServiceStatus", ClientOptions = clientOptions
 }, cancellationToken);