Module: Restiny::Api::Authentication
Constant Summary collapse
- CODE_RESPONSE_TYPE =
'code'
- AUTH_CODE_GRANT_TYPE =
'authorization_code'
Instance Method Summary collapse
- #get_authorise_url(redirect_url: nil, state: nil) ⇒ Object
- #request_access_token(code, redirect_url: nil) ⇒ Object
Methods included from Base
Instance Method Details
#get_authorise_url(redirect_url: nil, state: nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/restiny/api/authentication.rb', line 15 def (redirect_url: nil, state: nil) check_oauth_client_id params = { response_type: CODE_RESPONSE_TYPE, client_id: @oauth_client_id, state: state || SecureRandom.hex(15) } params['redirect_url'] = redirect_url unless redirect_url.nil? query = params.map { |k, v| "#{k}=#{v}" }.join('&') "#{BUNGIE_URL}/en/oauth/authorize/?#{query}" end |
#request_access_token(code, redirect_url: nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/restiny/api/authentication.rb', line 31 def request_access_token(code, redirect_url: nil) check_oauth_client_id params = { code: code, grant_type: AUTH_CODE_GRANT_TYPE, client_id: @oauth_client_id } params['redirect_url'] = redirect_url unless redirect_url.nil? response = http_client.post('/platform/app/oauth/token/', form: params) response.raise_for_status response.json rescue HTTPX::Error => e handle_authentication_error(e) end |