Module: Bullhorn::Rest::Authentication
- Included in:
- Client
- Defined in:
- lib/bullhorn/rest/authentication.rb
Overview
Instance Method Summary collapse
- #auth_conn ⇒ Object
- #authenticate ⇒ Object
- #authenticated? ⇒ Boolean
- #authorize ⇒ Object
- #login ⇒ Object
- #retrieve_tokens ⇒ Object
Instance Method Details
#auth_conn ⇒ Object
7 8 9 |
# File 'lib/bullhorn/rest/authentication.rb', line 7 def auth_conn @auth_conn ||= Faraday.new end |
#authenticate ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bullhorn/rest/authentication.rb', line 58 def authenticate unless rest_token unless access_token unless auth_code end retrieve_tokens end login end end |
#authenticated? ⇒ Boolean
71 72 73 74 |
# File 'lib/bullhorn/rest/authentication.rb', line 71 def authenticated? # TODO: check expires !!rest_token end |
#authorize ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/bullhorn/rest/authentication.rb', line 11 def url = "https://auth.bullhornstaffing.com/oauth/authorize" params = { client_id: client_id, username: username, password: password, action: 'Login', response_type: 'code' } res = auth_conn.get url, params location = res.headers['location'] @auth_code = CGI::parse(URI(location).query)["code"].first end |
#login ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bullhorn/rest/authentication.rb', line 44 def login url = "https://rest.bullhornstaffing.com/rest-services/login" params = { version: '*', access_token: access_token } response = auth_conn.get url, params hash = JSON.parse(response.body) @rest_token = hash['BhRestToken'] @rest_url = hash['restUrl'] end |
#retrieve_tokens ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bullhorn/rest/authentication.rb', line 27 def retrieve_tokens url = "https://auth.bullhornstaffing.com/oauth/token" params = { grant_type: 'authorization_code', code: auth_code, client_id: client_id, client_secret: client_secret } res = auth_conn.post url, params hash = JSON.parse(res.body) @access_token = hash['access_token'] @access_token_expires_in = hash['expires_in'] @refresh_token = hash['refresh_token'] end |