Пример #1
0
        /// <summary>
        /// Client uses this method to apply a Signed Header to a S3Request. Allows Client to send an Authorized S3Request directly to Amazon - without the Secret Key.
        /// </summary>
        /// <param name="request"></param>
        /// <param name="authResponse"></param>
        public static void ApplySignedHeader(this S3Request request, SignedHeaderResponse authResponse)
        {
            if (authResponse.IsAuthorized == false)
                throw new SecurityException("Unable to apply AuthorizationResponse to S3Request. The S3 AuthenticationResponse you received was not authorized.");

            request.WebRequest.Headers.Clear();
            request.WebRequest.Headers.Add(authResponse.Headers);
        }
Пример #2
0
        /// <summary>
        /// App Server uses this method to sign a SignedHeaderRequest with the Secret Key.  App Server sends SignedHeaderResponse back to Client.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="authRequest"></param>
        /// <returns></returns>
        public static SignedHeaderResponse ApproveSignedHeaderRequest(this S3Service service, SignedHeaderRequest authRequest)
        {
            // Create matching HTTP Request, so we can authorize for our requestor
            var httpRequest = (HttpWebRequest)HttpWebRequest.Create(authRequest.RequestURI);
            httpRequest.Headers.Add(authRequest.Headers);
            httpRequest.Method = authRequest.Method;
            httpRequest.ContentType = authRequest.ContentType;

            // Authorize with Secret Key
            service.AuthorizeRequest(null, httpRequest, authRequest.BucketName);

            var authResponse = new SignedHeaderResponse()
            {
                Headers = httpRequest.Headers,
                IsAuthorized = true
            };

            return authResponse;
        }