Class: FattureInCloud_Ruby_Sdk::OAuth2AuthorizationCodeManager
- Inherits:
-
OAuth2Manager
- Object
- OAuth2Manager
- FattureInCloud_Ruby_Sdk::OAuth2AuthorizationCodeManager
- Defined in:
- lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb
Overview
The OAuth2AuthorizationCodeManager class is used to manage the OAuth2 authorization code flow.
Instance Attribute Summary collapse
-
#base_uri ⇒ Object
Returns the value of attribute base_uri.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
Instance Method Summary collapse
-
#fetch_token(code) ⇒ OAuth2TokenResponse
Get the access token.
-
#get_authorization_url(scopes, state) ⇒ String
Get the authorization url.
-
#get_params_from_url(url) ⇒ OAuth2AuthorizationCodeParams
Get url parameters.
-
#initialize(client_id, client_secret, redirect_uri, base_uri = 'https://api-v2.fattureincloud.it') ⇒ OAuth2AuthorizationCodeManager
constructor
Initializes a new instance of the OAuth2AuthorizationCodeManager class.
-
#refresh_token(refresh_token) ⇒ OAuth2TokenResponse
Get the refresh token.
Methods inherited from OAuth2Manager
#execute_post, get_scope_string
Constructor Details
#initialize(client_id, client_secret, redirect_uri, base_uri = 'https://api-v2.fattureincloud.it') ⇒ OAuth2AuthorizationCodeManager
Initializes a new instance of the OAuth2AuthorizationCodeManager class.
46 47 48 49 50 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 46 def initialize(client_id, client_secret, redirect_uri, base_uri = 'https://api-v2.fattureincloud.it') super client_id, base_uri @client_secret = client_secret @redirect_uri = redirect_uri end |
Instance Attribute Details
#base_uri ⇒ Object
Returns the value of attribute base_uri.
39 40 41 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 39 def base_uri @base_uri end |
#client_id ⇒ Object
Returns the value of attribute client_id.
39 40 41 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 39 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
39 40 41 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 39 def client_secret @client_secret end |
#redirect_uri ⇒ Object
Returns the value of attribute redirect_uri.
39 40 41 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 39 def redirect_uri @redirect_uri end |
Instance Method Details
#fetch_token(code) ⇒ OAuth2TokenResponse
Get the access token.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 75 def fetch_token(code) token_uri = "#{@base_uri}/oauth/token" data = { 'grant_type': 'authorization_code', 'client_id': @client_id, 'client_secret': @client_secret, 'redirect_uri': @redirect_uri, 'code': code, } json = execute_post(token_uri, data) OAuth2TokenResponse.new(json["token_type"], json['access_token'], json['refresh_token'], json['expires_in']) end |
#get_authorization_url(scopes, state) ⇒ String
Get the authorization url.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 56 def (scopes, state) = "#{@base_uri}/oauth/authorize" scope_string = OAuth2Manager.get_scope_string(scopes) params = { 'response_type': 'code', 'client_id': @client_id, 'redirect_uri': @redirect_uri, 'scope': scope_string, 'state': state } url = URI.parse() url.query = URI.encode_www_form(params) url.to_s end |
#get_params_from_url(url) ⇒ OAuth2AuthorizationCodeParams
Get url parameters.
111 112 113 114 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 111 def get_params_from_url(url) url_obj = URI::decode_www_form(URI.parse(url).query).to_h OAuth2AuthorizationCodeParams.new(url_obj['code'], url_obj['state']) end |
#refresh_token(refresh_token) ⇒ OAuth2TokenResponse
Get the refresh token.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/fattureincloud_ruby_sdk/oauth2/oauth2.rb', line 93 def refresh_token(refresh_token) token_uri = "#{@base_uri}/oauth/token" data = { 'grant_type': 'refresh_token', 'client_id': @client_id, 'client_secret': @client_secret, 'refresh_token': refresh_token, } json = execute_post(token_uri, data) OAuth2TokenResponse.new(json["token_type"], json['access_token'], json['refresh_token'], json['expires_in']) end |