Class: DuoSecurity::API
- Inherits:
-
Object
- Object
- DuoSecurity::API
- Includes:
- HTTParty
- Defined in:
- lib/duo_security/api.rb
Defined Under Namespace
Classes: UnknownUser
Constant Summary collapse
- FACTORS =
["auto", "passcode", "phone", "sms", "push"]
Instance Method Summary collapse
- #auth(user, factor, factor_params) ⇒ Object
- #check ⇒ Object
-
#initialize(host, secret_key, integration_key) ⇒ API
constructor
A new instance of API.
- #ping ⇒ Object
- #preauth(user) ⇒ Object
Constructor Details
#initialize(host, secret_key, integration_key) ⇒ API
Returns a new instance of API.
13 14 15 16 17 18 19 |
# File 'lib/duo_security/api.rb', line 13 def initialize(host, secret_key, integration_key) @host = host @skey = secret_key @ikey = integration_key self.class.base_uri "https://#{@host}/rest/v1" end |
Instance Method Details
#auth(user, factor, factor_params) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/duo_security/api.rb', line 42 def auth(user, factor, factor_params) raise ArgumentError.new("Factor should be one of #{FACTORS.join(", ")}") unless FACTORS.include?(factor) params = {"user" => user, "factor" => factor}.merge(factor_params) response = post("/auth",params) response["response"]["result"] == "allow" end |
#check ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/duo_security/api.rb', line 26 def check auth = sign("get", @host, "/rest/v1/check", {}, @skey, @ikey) response = self.class.get("/check", headers: {"Authorization" => auth}) # TODO use parsed_response.fetch(...) when content-type is set correctly response["response"] == "valid" end |
#ping ⇒ Object
21 22 23 24 |
# File 'lib/duo_security/api.rb', line 21 def ping response = self.class.get("/ping") response.parsed_response.fetch("response") == "pong" end |
#preauth(user) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/duo_security/api.rb', line 34 def preauth(user) response = post("/preauth", {"user" => user})["response"] raise UnknownUser, response.fetch("status") if response.fetch("result") == "enroll" return response end |