Class: ChinoRuby::Auth

Inherits:
ChinoBaseAPI show all
Defined in:
lib/chino_ruby/classes.rb

Instance Method Summary collapse

Methods inherited from ChinoBaseAPI

#delete_resource, #get_resource, #initialize, #parse_response, #patch_resource, #post_resource, #post_resource_with_string_result, #put_resource, #return_uri

Methods inherited from CheckValues

#check_boolean, #check_int, #check_json, #check_string

Constructor Details

This class inherits a constructor from ChinoRuby::ChinoBaseAPI

Instance Method Details

#login_authentication_code(code, redirect_url, application_id, application_secret) ⇒ Object



366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/chino_ruby/classes.rb', line 366

def (code, redirect_url, application_id, application_secret)
  check_string(code)
  check_string(redirect_url)
  check_string(application_id)
  check_string(application_secret)
  uri = return_uri("/auth/token/")
  req = Net::HTTP::Post.new(uri.path)
  req.basic_auth application_id, application_secret
  req.set_form_data([["code", code], ["redirect_uri", redirect_url], ["grant_type", "authorization_code"], ["scope", "read write"], ["client_id", application_id], ["client_secret", application_secret]])
  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
    http.request(req)
  }
  usr = LoggedUser.new
  usr.from_json((parse_response(res)['data']).to_json)
  usr
end

#login_password(username, password, application_id, application_secret) ⇒ Object



349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
# File 'lib/chino_ruby/classes.rb', line 349

def (username, password, application_id, application_secret)
  check_string(username)
  check_string(password)
  check_string(application_id)
  check_string(application_secret)
  uri = return_uri("/auth/token/")
  req = Net::HTTP::Post.new(uri.path)
  req.basic_auth application_id, application_secret
  req.set_form_data([["username", username], ["password", password], ["grant_type", "password"]])
  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
    http.request(req)
  }
  usr = LoggedUser.new
  usr.from_json((parse_response(res)['data']).to_json)
  usr
end

#logout(token, application_id, application_secret) ⇒ Object



399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/chino_ruby/classes.rb', line 399

def logout(token, application_id, application_secret)
  check_string(token)
  check_string(application_id)
  check_string(application_secret)
  uri = return_uri("/auth/revoke_token/")
  req = Net::HTTP::Post.new(uri.path)
  req.basic_auth application_id, application_secret
  req.set_form_data([["token", token], ["client_id", application_id], ["client_secret", application_secret]])
  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
    http.request(req)
  }
  parse_response(res)['result']

end

#refresh_token(refresh_token, application_id, application_secret) ⇒ Object



383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/chino_ruby/classes.rb', line 383

def refresh_token(refresh_token, application_id, application_secret)
  check_string(refresh_token)
  check_string(application_id)
  check_string(application_secret)
  uri = return_uri("/auth/token/")
  req = Net::HTTP::Post.new(uri.path)
  req.basic_auth application_id, application_secret
  req.set_form_data([["refresh_token", refresh_token], ["client_id", application_id], ["client_secret", application_secret], ["grant_type", "refresh_token"]])
  res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) {|http|
    http.request(req)
  }
  usr = LoggedUser.new
  usr.from_json((parse_response(res)['data']).to_json)
  usr
end