Class: DocusignDtr::Auth::Code
- Defined in:
- lib/docusign_dtr/auth/code.rb
Instance Attribute Summary collapse
-
#userinfo ⇒ Object
Returns the value of attribute userinfo.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(integrator_key:, secret_key:, redirect_uri:, test_mode: true, state: nil, application: 'docusign_dtr') ⇒ Code
constructor
rubocop:disable Metrics/ParameterLists.
- #refresh_token ⇒ Object
-
#request_token(code:, state: nil) ⇒ Object
rubocop:enable Metrics/ParameterLists.
- #user_info ⇒ Object
Methods inherited from Base
#grant_url, #parse_url_response
Constructor Details
#initialize(integrator_key:, secret_key:, redirect_uri:, test_mode: true, state: nil, application: 'docusign_dtr') ⇒ Code
rubocop:disable Metrics/ParameterLists
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/docusign_dtr/auth/code.rb', line 7 def initialize(integrator_key:, secret_key:, redirect_uri:, test_mode: true, state: nil, application: 'docusign_dtr') @config = DocusignDtr::Models::AuthConfig.new( application: application, integrator_key: integrator_key, redirect_uri: redirect_uri, secret_key: secret_key, state: state || SecureRandom.uuid, test_mode: test_mode ) end |
Instance Attribute Details
#userinfo ⇒ Object
Returns the value of attribute userinfo.
5 6 7 |
# File 'lib/docusign_dtr/auth/code.rb', line 5 def userinfo @userinfo end |
Instance Method Details
#refresh_token ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/docusign_dtr/auth/code.rb', line 33 def refresh_token raise 'No token to refresh' unless @token_response&.refresh_token params = { grant_type: :refresh_token, refresh_token: @token_response.refresh_token } response = self.class.post("#{base_uri}oauth/token", query: params, headers: headers, timeout: 60) handle_error(response) @token_response = DocusignDtr::Models::AuthTokenResponse.new(response.parsed_response) end |
#request_token(code:, state: nil) ⇒ Object
rubocop:enable Metrics/ParameterLists
24 25 26 27 28 29 30 31 |
# File 'lib/docusign_dtr/auth/code.rb', line 24 def request_token(code:, state: nil) raise 'State does not match. Possible CSRF!' if state && state != @config.state params = { grant_type: :authorization_code, code: code } response = self.class.post(auth_uri, query: params, headers: headers, timeout: 60) handle_error(response) @token_response = DocusignDtr::Models::AuthTokenResponse.new(response.parsed_response) end |
#user_info ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/docusign_dtr/auth/code.rb', line 42 def user_info raise 'No token to obtain userinfo' unless @token_response&.access_token response = self.class.get("#{base_uri}oauth/userinfo", headers: user_info_headers, timeout: 60) handle_error(response) @userinfo = DocusignDtr::Models::Userinfo.new(response.parsed_response) end |