Class: OneID
- Inherits:
-
Object
- Object
- OneID
- Defined in:
- lib/oneid.rb
Instance Method Summary collapse
- #confirm(uid, token, message) ⇒ Object
-
#initialize(api_id = nil, api_key = nil, server = "") ⇒ OneID
constructor
A new instance of OneID.
- #make_nonce ⇒ Object
- #register ⇒ Object
- #success?(response) ⇒ Boolean
- #validate(payload) ⇒ Object
Constructor Details
#initialize(api_id = nil, api_key = nil, server = "") ⇒ OneID
Returns a new instance of OneID.
5 6 7 8 9 10 |
# File 'lib/oneid.rb', line 5 def initialize(api_id = nil, api_key = nil, server = "") @api_id = api_id @api_key = api_key @keychain_server = sprintf("https://keychain%s.oneid.com", server) @repo_server = sprintf("https://account%s.oneid.com/repo", server) end |
Instance Method Details
#confirm(uid, token, message) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/oneid.rb', line 43 def confirm(uid, token, ) result = post(@repo_server, "send_2fa", { "two_factor_token" => token, "message" => }) result["uid"] = uid self.validate(result) end |
#make_nonce ⇒ Object
16 17 18 |
# File 'lib/oneid.rb', line 16 def make_nonce() post(@keychain_server, "make_nonce") end |
#register ⇒ Object
12 13 14 |
# File 'lib/oneid.rb', line 12 def register() post(@keychain_server, "register") end |
#success?(response) ⇒ Boolean
39 40 41 |
# File 'lib/oneid.rb', line 39 def success?(response) response.has_key?("errorcode") ? response["errorcode"] == 0 : false end |
#validate(payload) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/oneid.rb', line 20 def validate(payload) if payload.is_a? String payload = JSON.parse(payload) end data = { "nonces" => payload["nonces"], "uid" => payload["uid"] } if payload.has_key?("attr_claim_tokens") data["attr_claim_tokens"] = payload["attr_claim_tokens"] end response = post(@keychain_server, "validate", data) response["valid"] = self.success?(response) payload.merge!(response) end |