Exemplo n.º 1
0
        /// <summary>
        /// Client can convert any S3Request to a SignedHeaderRequest.  SignedHeaderRequest can be serialized & sent to App Server where it can be signed with the Secret Key.
        /// </summary>
        /// <param name="s3request"></param>
        /// <returns></returns>
        public static SignedHeaderRequest BuildSignedHeaderRequest(this S3Request s3request)
        {
            var httpRequest = s3request.WebRequest;

            var authRequest = new SignedHeaderRequest()
            {
                // Bucket
                BucketName = s3request.BucketName,

                // HTTP Stuff
                Headers = httpRequest.Headers,
                Method = httpRequest.Method,
                ContentType = httpRequest.ContentType,
                RequestURI = httpRequest.RequestUri.ToString()
            };

            return authRequest;
        }
Exemplo n.º 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;
        }