Class: DocusignDtr::Auth::Code
- Inherits:
-
Base
- Object
- Base
- DocusignDtr::Auth::Code
show all
- Defined in:
- lib/docusign_dtr/auth/code.rb
Instance Attribute Summary
Attributes inherited from Base
#config, #token_response
Instance Method Summary
collapse
Methods inherited from Base
#grant_url, #parse_url_response
Constructor Details
#initialize(integrator_key:, secret_key:, redirect_uri:, test_mode: true, application: 'docusign_dtr') ⇒ Code
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/docusign_dtr/auth/code.rb', line 5
def initialize(integrator_key:,
secret_key:,
redirect_uri:,
test_mode: true,
application: 'docusign_dtr')
@config = DocusignDtr::Models::AuthConfig.new(
application: application,
integrator_key: integrator_key,
redirect_uri: redirect_uri,
secret_key: secret_key,
state: SecureRandom.uuid,
test_mode: test_mode
)
end
|
Instance Method Details
#refresh_token ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/docusign_dtr/auth/code.rb', line 28
def refresh_token
raise 'No token to refresh' unless @token_response&.access_token
params = { grant_type: :refresh_token, refresh_token: @token_response.access_token }
response = self.class.post("#{base_uri}oauth/token", query: params, headers: , timeout: 60)
handle_error(response.code) if response.code != 200
@token_response = DocusignDtr::Models::AuthTokenResponse.new(response.parsed_response)
end
|
#request_token(code:, state: nil) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/docusign_dtr/auth/code.rb', line 20
def request_token(code:, state: nil)
raise 'State does ont match. Possible CSRF!' if state && state != @config.state
params = { grant_type: :authorization_code, code: code }
response = self.class.post(auth_uri, query: params, headers: , timeout: 60)
handle_error(response.code) if response.code != 200
@token_response = DocusignDtr::Models::AuthTokenResponse.new(response.parsed_response)
end
|