Skip to content

bilby91/HMACSigner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HMACSigner

[CI Status](https://travis-ci.org/Martin Fernandez/HMACSigner) Version License Platform

Usage

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

To sign a request, the following steps are taken:

  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")

Requirements

Installation

HMACSigner is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "HMACSigner"

Author

Martin Fernandez fmartin91@gmail.com

License

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

About

HMACSigner signs your requests using HMAC + SHA1

Resources

License

Stars

Watchers

Forks

Packages

No packages published