Class: RGData::Authentication
- Includes:
- HTTParty
- Defined in:
- lib/rgdata/authentication.rb
Class Method Summary collapse
-
.request_url(scope, redirect_uri) ⇒ Object
Construct a url for requesting authentication.
- .swap_authorization_code(authorization_code, redirect_uri) ⇒ Object
- .swap_refresh_token(refresh_token) ⇒ Object
Class Method Details
.request_url(scope, redirect_uri) ⇒ Object
Construct a url for requesting authentication.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rgdata/authentication.rb', line 9 def request_url(scope, redirect_uri) method = Net::HTTP::Get path = [:base_uri] + '/auth' query = { client_id: RGData.config.client_id, redirect_uri: redirect_uri, scope: scope, response_type: 'code', } query.verify_keys_present_and_values_not_blank(:client_id, :redirect_uri, :scope, :response_type) request = HTTParty::Request.new(method, path, query: query) URI.unescape(request.uri.to_s) end |
.swap_authorization_code(authorization_code, redirect_uri) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rgdata/authentication.rb', line 23 def (, redirect_uri) body = { client_id: RGData.config.client_id, client_secret: RGData.config.client_secret, code: , grant_type: 'authorization_code', redirect_uri: redirect_uri } body.verify_keys_present_and_values_not_blank(:client_secret, :client_id, :code, :grant_type, :redirect_uri) post('/token', body: body) end |
.swap_refresh_token(refresh_token) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rgdata/authentication.rb', line 35 def swap_refresh_token(refresh_token) body = { client_id: RGData.config.client_id, client_secret: RGData.config.client_secret, refresh_token: refresh_token, grant_type: 'refresh_token', } body.verify_keys_present_and_values_not_blank(:refresh_token, :grant_type, :client_secret, :client_id) post('/token', body: body) end |