https://github.com/mustafaturan/oauth2_hmac_sign
Simply generate and verify signatures for Oauth v2 HTTP MAC authentication for 'SHA1' and 'SHA256' algorithms.
https://github.com/mustafaturan/oauth2_hmac_sign
Last synced: 8 months ago
JSON representation
Simply generate and verify signatures for Oauth v2 HTTP MAC authentication for 'SHA1' and 'SHA256' algorithms.
- Host: GitHub
- URL: https://github.com/mustafaturan/oauth2_hmac_sign
- Owner: mustafaturan
- Created: 2015-08-01T20:06:20.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2021-01-13T06:37:53.000Z (over 4 years ago)
- Last Synced: 2024-05-01T20:47:10.194Z (over 1 year ago)
- Language: Ruby
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Oauth2HmacSign
[](https://travis-ci.org/mustafaturan/oauth2_hmac_sign) [](https://codeclimate.com/github/mustafaturan/oauth2_hmac_sign)A single signature generator and validator Oauth v2 HTTP message authentication code(MAC) authentication. It simply generates and verify signatures for Oauth v2 HTTP MAC authentication for 'SHA1' and 'SHA256' algorithms. Please visit https://tools.ietf.org/html/draft-ietf-oauth-v2-http-mac-01 for spec specifications.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'oauth2_hmac_sign'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install oauth2_hmac_sign
## Usage
### For generating
```ruby
algorithm = 'hmac-sha-256' # 'hmac-sha-256' or 'hmac-sha-1'
key = 'demo_key' # your key
method = 'post' # http method for request -> get, post, head, patch, ...
uri = '/request?b5=%3D%253D&a3=a&c%40=&a2=r%20b&c2&a3=2+q' # request uri
host = 'example.com' # server host name
port = 443 # default is 443
ext = 'a,b,c' # can be nil
ts, nonce, ext, mac = Oauth2HmacSign::Signature.generate(
algorithm, key, method, uri, host, port, ext
)
# returns multiple information
# ts = timestamp
# nonce = unique string
# ext = if nil send as input than returns empty string else returns the same string as input
# mac = mac signature for the given parameters
```### For verifying
```ruby
Oauth2HmacSign::Signature.is_valid?(
mac,
algorithm,
key,
ts,
nonce,
method,
uri,
host,
port,
ext
)# returns
# true for valid
# false for invalid
```
## Contributing1. Fork it ( https://github.com/mustafaturan/oauth2_hmac_sign/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request