[](https://travis-ci.org/Martin Fernandez/HMACSigner)
HMACSigner signs your requests using HMAC + SHA1. It was designed to work with ApiAuth gem.
To sign a request, the following steps are taken:
- Calculates a canonical string like this 'HTTPMethod,Content-Type,MD5(Body),URI,HTTPDate'
- Hashes the canonical string using the secret
- Adds the 'Authorization' header with "APIAuth identifier:hashedString"
To use it:
Objective-C
NSURL *url = [NSURL URLWithString:@"https://api.domain.com/users/me"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPMethod = @"POST";
request.HTTPBody = [@"Message" dataUsingEncoding:NSUTF8StringEncoding];
[request setValue:@"application/text" forHTTPHeaderField:@"Content-Type"];
[request signWithAccessIdentifier:@"userId" andSecret:@"secret"];
Swift
let request = NSMutableURLRequest( url: URL(string: "https://api.domain.com/users/me"))
request.httpMethod = "POST"
request.httpBody = "Message".data(using: .utf8)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.sign(withAccessIdentifier: "userId", andSecret: "secret")
HMACSigner is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "HMACSigner"
Martin Fernandez fmartin91@gmail.com
HMACSigner is available under the MIT license. See the LICENSE file for more info.