Class: DeviseProxy::Authenticator
- Inherits:
-
Object
- Object
- DeviseProxy::Authenticator
- Defined in:
- lib/devise-proxy/authenticator.rb
Constant Summary collapse
- @@POST_SIGN =
"/users/sign_in.json"- @@POST_WS =
"/external/rd"
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
- #authenticate(email, password) ⇒ Object
-
#initialize(host = 'localhost', port = 3000) ⇒ Authenticator
constructor
A new instance of Authenticator.
Constructor Details
#initialize(host = 'localhost', port = 3000) ⇒ Authenticator
Returns a new instance of Authenticator.
14 15 16 17 |
# File 'lib/devise-proxy/authenticator.rb', line 14 def initialize(host = 'localhost', port = 3000) @host = host @port = port end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/devise-proxy/authenticator.rb', line 8 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
9 10 11 |
# File 'lib/devise-proxy/authenticator.rb', line 9 def port @port end |
Instance Method Details
#authenticate(email, password) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/devise-proxy/authenticator.rb', line 19 def authenticate(email, password) @credentials = { "user" => { "email" => email, "password" => password } }.to_json sig = Net::HTTP::Post.new(@@POST_SIGN, initheader = {'Content-Type' => 'application/json'}) sig.body = @credentials http = Net::HTTP.new(@host, @port).start resp1 = http.request(sig) # puts "Response: #{resp1.code} , Message: #{resp1.message} , Body: #{resp1.body}" result = [] json_resp = JSON.parse(resp1.body) #puts json_resp.inspect @auth_token = json_resp['auth_token'] if resp1.code == "200" then puts "logged in" @req_body = { "device" => { "name" => "device_json", "operating_system_id" => "7", "hash_string" => "jfsg3k4ovj0j02jv" }, "auth_token" => @auth_token }.to_json req = Net::HTTP::Post.new(@@POST_WS, initheader = {'Content-Type' =>'application/json'}) req.body = @req_body response = http.request(req) # puts "Response: #{response.code} , Message: #{response.message} , Body: #{response.body}" headers = {} sub_response.each_header do |k,v| headers[k] = v unless k.to_s =~ /content-length|transfer-encoding/i end result = [response.code, headers, response.body] else headers = {} resp1.each_header do |k,v| headers[k] = v unless k.to_s =~ /content-length|transfer-encoding/i end result = [resp1.code, headers, resp1.body, @auth_token] end return result end |