interswitch-rest-secure 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/isw_rest_secure.rb +111 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f8b5023bc73312da2bae20900abca5fe40f56f52
|
4
|
+
data.tar.gz: b2933f5b6d5a7eb376b31fa365f4f453eb766415
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 84cb8ee3220f0b339d15a55e93d79fb8ec9eceb8621952a0ccaf724ac60ac6dc359a286d1bf96d0d8c55132f8a99f5cd1e0dc1a8a12443e7e6451093a4aa758f
|
7
|
+
data.tar.gz: 92125c6c2e97225c0e338e7d220c9ba13e1be20e86159ebdf6dc6a036ddb85ff18637e0db6612219446ca19b4adfffcf7e59e65778381285c7597ff3062cc967
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require 'rack'
|
3
|
+
require "open-uri"
|
4
|
+
require "digest"
|
5
|
+
require 'active_support/core_ext/string'
|
6
|
+
|
7
|
+
class IswRestSecure
|
8
|
+
|
9
|
+
def self.generate_auth_headers(hash={})
|
10
|
+
|
11
|
+
if !valid_params(hash)
|
12
|
+
return nil
|
13
|
+
end
|
14
|
+
|
15
|
+
client_id = hash[:client_id]
|
16
|
+
secret = hash[:secret]
|
17
|
+
http_method = hash[:http_method]
|
18
|
+
url = hash[:url]
|
19
|
+
tran_parameters = hash[:tran_parameters]
|
20
|
+
content_type = hash[:content_type]
|
21
|
+
|
22
|
+
nonce = generate_nonce
|
23
|
+
authorization = generate_authorization client_id
|
24
|
+
timestamp = generate_timestamp
|
25
|
+
signature = generate_signature(client_id, secret, url, http_method, timestamp, nonce, tran_parameters )
|
26
|
+
|
27
|
+
headers = {
|
28
|
+
"Signature" => signature,
|
29
|
+
"Timestamp" => timestamp,
|
30
|
+
"Nonce" => nonce,
|
31
|
+
"Authorization" => authorization,
|
32
|
+
"SignatureMethod" => "SHA1",
|
33
|
+
"Content-Type" => content_type
|
34
|
+
}
|
35
|
+
|
36
|
+
return headers
|
37
|
+
|
38
|
+
rescue => e
|
39
|
+
puts "Error occured #{e.message}"
|
40
|
+
return nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.generate_signature( client_id, secret, url, http_method, timestamp, nonce, tran_parameters )
|
44
|
+
|
45
|
+
url = url.sub("http://", "https://")
|
46
|
+
encoded_url = Rack::Utils.escape(url).to_s
|
47
|
+
|
48
|
+
base_string = http_method + "&" +
|
49
|
+
encoded_url + "&" +
|
50
|
+
timestamp + "&" +
|
51
|
+
nonce + "&" +
|
52
|
+
client_id + "&" +
|
53
|
+
secret
|
54
|
+
|
55
|
+
temp_parameters = ""
|
56
|
+
if tran_parameters && tran_parameters.kind_of?(Array) && tran_parameters.count > 0
|
57
|
+
tran_parameters.each do |tran_parameter|
|
58
|
+
temp_parameters = temp_parameters + "&" + tran_parameter.to_s
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
full_string_to_be_signed = base_string + temp_parameters
|
63
|
+
signature = Base64.encode64((Digest::SHA1.new() << full_string_to_be_signed).digest).strip
|
64
|
+
|
65
|
+
return signature
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.generate_authorization(client_id)
|
69
|
+
"InterswitchAuth #{Base64.encode64(client_id)}"
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
def self.generate_timestamp
|
74
|
+
Time.now.to_i.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.generate_nonce
|
78
|
+
SecureRandom.random_number(99999999999999999999999).to_s
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
def self.valid_params(hash={})
|
84
|
+
|
85
|
+
if hash[:client_id].blank?
|
86
|
+
puts ">>>Empty client id supplied.."
|
87
|
+
return false
|
88
|
+
end
|
89
|
+
|
90
|
+
if hash[:secret].blank?
|
91
|
+
puts ">>>Empty secret supplied.."
|
92
|
+
return false
|
93
|
+
end
|
94
|
+
|
95
|
+
if hash[:http_method].blank?
|
96
|
+
puts ">>>Empty http method supplied.."
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
|
100
|
+
if hash[:url].blank?
|
101
|
+
puts ">>>Empty url supplied.."
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
|
105
|
+
return true
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interswitch-rest-secure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Raphael Okochu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A utility gem for generating Interswitch REST security headers.
|
14
|
+
email: ask4ralph@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/isw_rest_secure.rb
|
20
|
+
homepage: http://rubygems.org/gems/interswitch-rest-secure
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.1.9
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Generate your Interswitch REST headers.
|
44
|
+
test_files: []
|