Module: Eol::OAuth
- Included in:
- API
- Defined in:
- lib/eol/oauth.rb
Overview
rubocop:disable Metrics/ModuleLength
Instance Method Summary collapse
- #authorize_division ⇒ Object
-
#authorize_url(options = {}) ⇒ Object
Return URL for OAuth authorization.
- #authorized? ⇒ Boolean
-
#get_access_token(code, _options = {}) ⇒ Object
Return an access token from authorization.
-
#get_refresh_token(refresh_token) ⇒ Object
Return an access token from authorization via refresh token.
Instance Method Details
#authorize_division ⇒ Object
27 28 29 |
# File 'lib/eol/oauth.rb', line 27 def get("/Current/Me", no_division: true).results.first.current_division end |
#authorize_url(options = {}) ⇒ Object
Return URL for OAuth authorization
32 33 34 35 36 37 38 39 |
# File 'lib/eol/oauth.rb', line 32 def ( = {}) [:response_type] ||= "code" [:redirect_uri] ||= redirect_uri params = .merge() uri = URI("#{base_url}/api/oauth2/auth/") uri.query = URI.encode_www_form(params) uri.to_s end |
#authorized? ⇒ Boolean
18 19 20 21 22 23 24 25 |
# File 'lib/eol/oauth.rb', line 18 def # Do a test call, return false if 401 or any error code response = Eol.get("/Current/Me", no_division: true) response.results.first.present? rescue BadRequestException Eol.error "Not yet authorized" return false end |
#get_access_token(code, _options = {}) ⇒ Object
Return an access token from authorization
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/eol/oauth.rb', line 42 def get_access_token(code, = {}) conn = Faraday.new(url: base_url) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end params = access_token_params(code) conn.post do |req| req.url "/api/oauth2/token" req.body = params req.headers["Accept"] = "application/json" end end |
#get_refresh_token(refresh_token) ⇒ Object
Return an access token from authorization via refresh token
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/eol/oauth.rb', line 56 def get_refresh_token(refresh_token) conn = Faraday.new(url: config[:base_url]) do |faraday| faraday.request :url_encoded faraday.adapter Faraday.default_adapter end params = refresh_access_token_params(refresh_token) conn.post do |req| req.url "/api/oauth2/token" req.body = params req.headers["Accept"] = "application/json" req.headers["Content-Type"] = "application/x-www-form-urlencoded" end end |