HMACSigner 1.0.0

HMACSigner 1.0.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Nov 2016

Maintained by Martin Fernandez.



Usage

HMACSigner signs your requests using HMAC + SHA1. It was adesigned to work with ApiAuth gem.

Basically it does this

  1. Calculates a canonical string like this 'HTTPMethod,Content-Type,MD5(Body),URI,HTTPDate'
  2. Hashes the canonical string using the secret
  3. 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")

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Author

Martin Fernandez [email protected]

License

HMACSigner is available under the MIT license. See the LICENSE file for more info.