infobip-twofactor 1.0.1 → 1.0.3
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 +4 -4
- data/Guardfile +1 -1
- data/Rakefile +3 -0
- data/infobip-twofactor.gemspec +0 -3
- data/lib/infobip/twofactor/api.rb +28 -24
- data/lib/infobip/twofactor/version.rb +1 -1
- data/spec/twofactor_api_spec.rb +6 -7
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfbd3770741ba8e91f7360ef0950e720e6fee09d
|
4
|
+
data.tar.gz: 8f0f0b96891ca2a5142aaa4ef0089d56806bcde0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a6b51186e3a88c83da88ad069a82748e804279c1322f5d6a5a289108d9c3c5a83cb976c1e05e61827d96352ce5e1fdc7155fb4d66be6131a13a127ea6c746e9
|
7
|
+
data.tar.gz: ec8b79b164a173dece4aadfd8333cd6554583b06c9d436185087c277b3df1d3fc564811522c8f5bec09a6326879486269df9e72070bf6dbbab59d1197983179c
|
data/Guardfile
CHANGED
data/Rakefile
CHANGED
data/infobip-twofactor.gemspec
CHANGED
@@ -19,8 +19,6 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
# spec.add_runtime_dependency "blanket_wrapper"
|
23
|
-
spec.add_runtime_dependency "crib"
|
24
22
|
|
25
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
26
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -31,6 +29,5 @@ Gem::Specification.new do |spec|
|
|
31
29
|
spec.add_development_dependency "guard-bundler"
|
32
30
|
spec.add_development_dependency "terminal-notifier-guard"
|
33
31
|
spec.add_development_dependency "fakeweb"
|
34
|
-
# spec.add_development_dependency "pry-nav"
|
35
32
|
|
36
33
|
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
require 'JSON'
|
3
4
|
|
4
5
|
module Infobip
|
5
6
|
module Twofactor
|
@@ -12,41 +13,44 @@ module Infobip
|
|
12
13
|
def initialize(username, password, url, message_id, application_id)
|
13
14
|
raise "Missing message_id" unless message_id
|
14
15
|
raise "Missing application_id" unless application_id
|
15
|
-
#send auth reqest
|
16
|
-
@authorization_string = Base64.strict_encode64("#{username}:#{password}")
|
17
16
|
@message_id = message_id
|
18
17
|
@application_id = application_id
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
@
|
27
|
-
http.headers[:authorization] = "App #{@api_key}"
|
28
|
-
http.headers["content-type"] = "application/json"
|
29
|
-
end
|
30
|
-
|
18
|
+
@url = url
|
19
|
+
uri = URI.parse(@url+"/api-key")
|
20
|
+
@http = Net::HTTP.new(uri.host, 443)
|
21
|
+
@http.use_ssl = true
|
22
|
+
request = Net::HTTP::Post.new(uri.path)
|
23
|
+
request.basic_auth(username,password)
|
24
|
+
request["content-type"] = "application/json"
|
25
|
+
@api_key = @http.request(request).body.gsub('"','')
|
31
26
|
end
|
32
27
|
|
33
|
-
|
34
28
|
def send_pin(phone)
|
35
29
|
raise "Missing phone number" unless phone
|
36
30
|
raise "Missing message_id" unless @message_id
|
37
31
|
raise "Missing application_id" unless @application_id
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
32
|
+
uri = URI.parse(@url+"/pin")
|
33
|
+
request = Net::HTTP::Post.new(uri.path)
|
34
|
+
request["authorization"] = "App #{@api_key}"
|
35
|
+
request["content-type"] = "application/json"
|
36
|
+
request.body = {applicationId: @application_id, messageId: @message_id, to: phone}.to_json
|
37
|
+
response = JSON.parse @http.request(request).body
|
38
|
+
raise "Malformed two factor API response - no sms status field. Response was: #{response.inspect}" if (response["smsStatus"].nil?)
|
39
|
+
raise "Malformed two factor API response - no pin Id field. Response was: #{response.inspect}" if (response["pinId"].nil?)
|
40
|
+
raise "SMS not sent" unless (response["smsStatus"] == "MESSAGE_SENT")
|
41
|
+
@pin_id = response["pinId"]
|
43
42
|
response
|
44
43
|
end
|
45
44
|
|
46
45
|
def verify_pin(pin_id, pin)
|
47
46
|
raise "Missing pin id" unless pin_id
|
48
|
-
|
49
|
-
|
47
|
+
uri = URI.parse(@url+"/pin/#{pin_id}/verify")
|
48
|
+
request = Net::HTTP::Post.new(uri.path)
|
49
|
+
request["content-type"] = "application/json"
|
50
|
+
request["authorization"] = "App #{@api_key}"
|
51
|
+
request.body = {pin: pin}.to_json
|
52
|
+
response = JSON.parse @http.request(request).body
|
53
|
+
raise "Malformed two factor API response - no verified field. Response was: #{response.inspect}" if (response["verified"].nil?)
|
50
54
|
response
|
51
55
|
end
|
52
56
|
|
data/spec/twofactor_api_spec.rb
CHANGED
@@ -9,10 +9,9 @@ describe Infobip::Twofactor::API do
|
|
9
9
|
before do
|
10
10
|
@configuration = YAML.load_file("configuration.yml")
|
11
11
|
|
12
|
-
FakeWeb.register_uri(:post, "
|
13
|
-
FakeWeb.register_uri(:post, "
|
14
|
-
FakeWeb.register_uri(:post, "
|
15
|
-
|
12
|
+
FakeWeb.register_uri(:post, "https://ippdok:4%40SkK2*_@oneapi.infobip.com/2fa/1/api-key", status: ["200", "OK"], body: api_key_response_body)
|
13
|
+
FakeWeb.register_uri(:post, "https://oneapi.infobip.com/2fa/1/pin", response: api_send_pin_response)
|
14
|
+
FakeWeb.register_uri(:post, "https://oneapi.infobip.com/2fa/1/pin/2B29B71922B37D3C93F8CEBB85B9E3CF/verify", response: api_verify_pin_response)
|
16
15
|
@twofactor = Infobip::Twofactor::API.new(@configuration["username"], @configuration["password"], @configuration["url"], @configuration["message_id"], @configuration["application_id"])
|
17
16
|
end
|
18
17
|
|
@@ -25,13 +24,13 @@ describe Infobip::Twofactor::API do
|
|
25
24
|
|
26
25
|
it "should create a valid Send PIN request, given valid params" do
|
27
26
|
response = subject.send_pin("48790809242")
|
28
|
-
expect(response[
|
27
|
+
expect(response["smsStatus"]).to eq "MESSAGE_SENT"
|
29
28
|
end
|
30
29
|
|
31
30
|
it "should create a valid Verify PIN request, given valid params" do
|
32
31
|
response = subject.send_pin("48790809242")
|
33
32
|
response = subject.verify_pin("2B29B71922B37D3C93F8CEBB85B9E3CF", "1234")
|
34
|
-
expect(response[
|
33
|
+
expect(response["verified"]).to eq true
|
35
34
|
end
|
36
35
|
|
37
36
|
context "error handling" do
|
@@ -48,4 +47,4 @@ describe Infobip::Twofactor::API do
|
|
48
47
|
|
49
48
|
end
|
50
49
|
|
51
|
-
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infobip-twofactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- knx
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: crib
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: bundler
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|