For example, imagine that you want to sign the following request:
PUT /quotes/nelson HTTP/1.0
Content-Md5: c8fdb181845a4ca6b8fec737b3581d76
Content-Type: text/html
Date: Thu, 17 Nov 2005 18:49:58 GMT
X-Amz-Meta-Author: [email protected]
X-Amz-Magic: abracadabra
The canonical string to be signed is:
PUT\nc8fdb181845a4ca6b8fec737b3581d76\ntext/html\nThu, 17 Nov 2005 18:49:58 GMT\nx-amz-magic:abracadabra\nx-amz-meta-author:[email protected]\n/quotes/nelson
Suppose your AWS Access Key ID is "44CF9590006BF252F707" and your AWS Secret Access Key is "OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV".
The resulting signature would be "jZNOcbfWmD/A/f3hSvVzXZjM2HU=", and, you would add the Authorization header to your request to come up with the following result:
PUT /quotes/nelson HTTP/1.0
Authorization: AWS 44CF9590006BF252F707:jZNOcbfWmD/A/f3hSvVzXZjM2HU=
Content-Md5: c8fdb181845a4ca6b8fec737b3581d76
Content-Type: text/html
Date: Thu, 17 Nov 2005 18:49:58 GMT
X-Amz-Meta-Author: [email protected]
X-Amz-Magic: abracadabra
Client code testing my
AuthHmacSecret authHmacSecret = new AuthHmacSecret()
.accessId("44CF9590006BF252F707")
.secret("OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV");
AuthHmacClientFilter authHmacClientFilter = new AuthHmacClientFilter(authHmacSecret);
Client client = Client.create();
client.addFilter(new LoggingFilter());
WebResource resource;
String response;
resource = client.resource("http://localhost/quotes/nelson");
resource.addFilter(authHmacClientFilter);
response = resource.getRequestBuilder()
.header("Date", "Thu, 17 Nov 2005 18:49:58 GMT")
.header("X-Amz-Magic", "abracadabra")
.header("X-Amz-Meta-Author", "[email protected]")
.header("Content-Md5", "c8fdb181845a4ca6b8fec737b3581d76")
.type(MediaType.TEXT_HTML_TYPE)
.put(String.class);
Log statement from my library.
Aug 05, 2012 8:55:29 PM com.sun.jersey.api.client.filter.LoggingFilter log
INFO: 1 * Client out-bound request
1 > PUT http://localhost/quotes/nelson
1 > Date: Thu, 17 Nov 2005 18:49:58 GMT
1 > X-Amz-Magic: abracadabra
1 > X-Amz-Meta-Author: [email protected]
1 > Content-Md5: c8fdb181845a4ca6b8fec737b3581d76
1 > Content-Type: text/html
1 > Authorization: AWS jZNOcbfWmD/A/f3hSvVzXZjM2HU=