oneid 0.1
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/oneid.rb +57 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4dc6644baa28e71274937644fe63ec4fdee5d0b0
|
4
|
+
data.tar.gz: ef3187ac1af5fbb77af334174489b476bc73a7a0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7f8a2d132b213395888217a17ad2e845972fb39b32c7e1da80e7191cb49b142fe583194a31a7aebd6426d1c56d79d634b3774c0cf07ac03a331990ebe1697a9
|
7
|
+
data.tar.gz: 493c3aa3709586f51dbcd3feecc93221498b9bdbae69653b7d1f40247b57fdf8e159a8472721966eb7a541fafcb8847d3f36b8abe85537b946697913e471c8f7
|
data/lib/oneid.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class OneID
|
5
|
+
def initialize(api_id = nil, api_key = nil, server = "")
|
6
|
+
@api_id = api_id
|
7
|
+
@api_key = api_key
|
8
|
+
@keychain_server = sprintf("https://keychain%s.oneid.com", server)
|
9
|
+
end
|
10
|
+
|
11
|
+
def register()
|
12
|
+
post(@keychain_server, "register")
|
13
|
+
end
|
14
|
+
|
15
|
+
def make_nonce()
|
16
|
+
post(@keychain_server, "make_nonce")
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate(payload)
|
20
|
+
if payload.is_a? String
|
21
|
+
payload = JSON.parse(payload)
|
22
|
+
end
|
23
|
+
|
24
|
+
data = {
|
25
|
+
"nonces" => payload["nonces"],
|
26
|
+
"uid" => payload["uid"]
|
27
|
+
}
|
28
|
+
|
29
|
+
if payload.has_key?("attr_claim_tokens")
|
30
|
+
data["attr_claim_tokens"] = payload["attr_claim_tokens"]
|
31
|
+
end
|
32
|
+
|
33
|
+
response = post(@keychain_server, "validate", data)
|
34
|
+
response["valid"] = success?(response)
|
35
|
+
payload.merge!(response)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def post(server, method, data = {})
|
40
|
+
url = URI.parse(sprintf("%s/%s", server, method))
|
41
|
+
req = Net::HTTP::Post.new(url.path)
|
42
|
+
if @api_id && @api_key
|
43
|
+
req.basic_auth @api_id, @api_key
|
44
|
+
end
|
45
|
+
req.body = JSON.generate(data)
|
46
|
+
req.add_field("Content-Type", "application/json")
|
47
|
+
|
48
|
+
sock = Net::HTTP.new(url.host, url.port)
|
49
|
+
sock.use_ssl = true
|
50
|
+
response = sock.start { |http| http.request(req) }
|
51
|
+
JSON.parse(response.body)
|
52
|
+
end
|
53
|
+
|
54
|
+
def success?(response)
|
55
|
+
response.has_key?("errorcode") ? response["errorcode"] == 0 : false
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oneid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlos Rivera
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby gem for OneID authentication.
|
14
|
+
email: carlos@oneid.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/oneid.rb
|
20
|
+
homepage: https://developer.oneid.com/#Packages_Ruby
|
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.0.3
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Ruby gem for OneID authentication!
|
44
|
+
test_files: []
|