Skip to content

Commit 23bb97b

Browse files
committedNov 25, 2024·
pkce auth
2 parents f8d5f2b + 9b51fbf commit 23bb97b

11 files changed

+498
-473
lines changed
 

‎.github/workflows/rubyonrails.yml

+47-41
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
1-
# This workflow uses actions that are not certified by GitHub. They are
2-
# provided by a third-party and are governed by separate terms of service,
3-
# privacy policy, and support documentation.
4-
#
5-
# This workflow will install a prebuilt Ruby version, install dependencies, and
6-
# run tests and linters.
7-
name: "Ruby on Rails CI"
8-
on:
9-
push:
10-
branches: [ "master" ]
11-
pull_request:
12-
branches: [ "master" ]
13-
jobs:
14-
build:
15-
runs-on: ubuntu-latest
16-
17-
steps:
18-
- name: Checkout code
19-
uses: actions/checkout@v3
20-
21-
- name: Install Ruby and gems
22-
uses: ruby/setup-ruby@v1
23-
with:
24-
bundler-cache: true
25-
ruby-version: 3.1.2
26-
27-
- name: Run linter
28-
run: bundle exec rubocop --parallel
29-
30-
- name: Run tests
31-
run: |
32-
gem install docusign_esign
33-
gem install docusign_click
34-
ruby test/run_tests.rb
35-
env:
36-
CLIENT_ID: ${{ secrets.CLIENT_ID }}
37-
USER_ID: ${{ secrets.USER_ID }}
38-
SIGNER_EMAIL: ${{ secrets.SIGNER_EMAIL }}
39-
SIGNER_NAME: ${{ secrets.SIGNER_NAME }}
40-
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
41-
1+
# This workflow uses actions that are not certified by GitHub. They are
2+
# provided by a third-party and are governed by separate terms of service,
3+
# privacy policy, and support documentation.
4+
#
5+
# This workflow will install a prebuilt Ruby version, install dependencies, and
6+
# run tests and linters.
7+
name: "Ruby on Rails CI"
8+
on:
9+
push:
10+
branches: [ "master" ]
11+
pull_request:
12+
branches: [ "master" ]
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v3
20+
21+
- name: Install Ruby
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
bundler-cache: false
25+
ruby-version: 3.1.2
26+
27+
- name: Update rubygems
28+
run: gem update --system
29+
30+
- name: Install dependencies
31+
run: bundle install
32+
33+
- name: Run linter
34+
run: bundle exec rubocop --parallel
35+
36+
- name: Run tests
37+
run: |
38+
gem install docusign_esign
39+
gem install docusign_click
40+
ruby test/run_tests.rb
41+
env:
42+
CLIENT_ID: ${{ secrets.CLIENT_ID }}
43+
USER_ID: ${{ secrets.USER_ID }}
44+
SIGNER_EMAIL: ${{ secrets.SIGNER_EMAIL }}
45+
SIGNER_NAME: ${{ secrets.SIGNER_NAME }}
46+
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
47+
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
1-
class AdminApi::Aeg001CreateUserController < EgController
2-
include ApiCreator
3-
before_action -> { check_auth('Admin') }
4-
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Admin') }
5-
6-
def create
7-
args = {
8-
account_id: session['ds_account_id'],
9-
base_path: session['ds_base_path'],
10-
access_token: session['ds_access_token'],
11-
organization_id: session['organization_id']
12-
}
13-
#ds-snippet-start:Admin1Step5
14-
user_data = {
15-
user_name: param_gsub(params['user_name']),
16-
first_name: param_gsub(params['first_name']),
17-
last_name: param_gsub(params['last_name']),
18-
email: param_gsub(params['email']),
19-
auto_activate_memberships: true,
20-
accounts: [
21-
{
22-
id: args[:account_id],
23-
permission_profile: {
24-
id: request['permission_profile_id']
25-
},
26-
groups: [
27-
{
28-
id: request['group_id']
29-
}
30-
]
31-
}
32-
]
33-
}
34-
#ds-snippet-end:Admin1Step5
35-
36-
begin
37-
results = AdminApi::Eg001CreateUserService.new(args, user_data).worker
38-
39-
@title = @example['ExampleName']
40-
@message = @example['ResultsPageText']
41-
@json = results.to_json.to_json
42-
render 'ds_common/example_done'
43-
rescue DocuSign_Admin::ApiError => e
44-
handle_error(e)
45-
end
46-
end
47-
48-
def get
49-
super
50-
session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
51-
args = {
52-
account_id: session['ds_account_id'],
53-
base_path: session['ds_base_path'],
54-
access_token: session['ds_access_token']
55-
}
56-
57-
#ds-snippet-start:Admin1Step3
58-
accounts_api = create_account_api(args)
59-
@permission_profiles = accounts_api.list_permissions(args[:account_id]).permission_profiles
60-
#ds-snippet-end:Admin1Step3
61-
62-
#ds-snippet-start:Admin1Step4
63-
groups_api = create_group_api(args)
64-
@groups = groups_api.list_groups(args[:account_id]).groups
65-
#ds-snippet-end:Admin1Step4
66-
end
67-
end
1+
class AdminApi::Aeg001CreateUserController < EgController
2+
include ApiCreator
3+
before_action -> { check_auth('Admin') }
4+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Admin') }
5+
6+
def create
7+
args = {
8+
account_id: session['ds_account_id'],
9+
base_path: session['ds_base_path'],
10+
access_token: session['ds_access_token'],
11+
organization_id: session['organization_id']
12+
}
13+
#ds-snippet-start:Admin1Step5
14+
user_data = {
15+
user_name: param_gsub(params['user_name']),
16+
first_name: param_gsub(params['first_name']),
17+
last_name: param_gsub(params['last_name']),
18+
email: param_gsub(params['email']),
19+
auto_activate_memberships: true,
20+
accounts: [
21+
{
22+
id: args[:account_id],
23+
permission_profile: {
24+
id: param_gsub(params['permission_profile_id'])
25+
},
26+
groups: [
27+
{
28+
id: param_gsub(params['group_id'])
29+
}
30+
]
31+
}
32+
]
33+
}
34+
#ds-snippet-end:Admin1Step5
35+
36+
begin
37+
results = AdminApi::Eg001CreateUserService.new(args, user_data).worker
38+
39+
@title = @example['ExampleName']
40+
@message = @example['ResultsPageText']
41+
@json = results.to_json.to_json
42+
render 'ds_common/example_done'
43+
rescue DocuSign_Admin::ApiError => e
44+
handle_error(e)
45+
end
46+
end
47+
48+
def get
49+
super
50+
session[:organization_id] = AdminApi::GetDataService.new(session).get_organization_id if session[:organization_id].nil?
51+
args = {
52+
account_id: session['ds_account_id'],
53+
base_path: session['ds_base_path'],
54+
access_token: session['ds_access_token']
55+
}
56+
57+
#ds-snippet-start:Admin1Step3
58+
accounts_api = create_account_api(args)
59+
@permission_profiles = accounts_api.list_permissions(args[:account_id]).permission_profiles
60+
#ds-snippet-end:Admin1Step3
61+
62+
#ds-snippet-start:Admin1Step4
63+
groups_api = create_group_api(args)
64+
@groups = groups_api.list_groups(args[:account_id]).groups
65+
#ds-snippet-end:Admin1Step4
66+
end
67+
end
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
class Clickwrap::Ceg001CreateClickwrapController < EgController
2-
before_action -> { check_auth('Click') }
3-
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Click') }
4-
5-
def create
6-
args = {
7-
account_id: session[:ds_account_id],
8-
base_path: session[:ds_base_path],
9-
access_token: session[:ds_access_token],
10-
doc_pdf: File.join('data', Rails.configuration.doc_terms_pdf),
11-
clickwrap_name: request[:clickwrapName]
12-
}
13-
14-
results = Clickwrap::Eg001CreateClickwrapService.new(args).worker
15-
16-
session[:clickwrap_id] = results.clickwrap_id
17-
session[:clickwrap_name] = results.clickwrap_name
18-
19-
@title = @example['ExampleName']
20-
@message = format_string(@example['ResultsPageText'], results.clickwrap_name)
21-
@json = results.to_json.to_json
22-
render 'ds_common/example_done'
23-
end
24-
end
1+
class Clickwrap::Ceg001CreateClickwrapController < EgController
2+
before_action -> { check_auth('Click') }
3+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 1, 'Click') }
4+
5+
def create
6+
args = {
7+
account_id: session[:ds_account_id],
8+
base_path: session[:ds_base_path],
9+
access_token: session[:ds_access_token],
10+
doc_pdf: File.join('data', Rails.configuration.doc_terms_pdf),
11+
clickwrap_name: param_gsub(params[:clickwrapName])
12+
}
13+
14+
results = Clickwrap::Eg001CreateClickwrapService.new(args).worker
15+
16+
session[:clickwrap_id] = results.clickwrap_id
17+
session[:clickwrap_name] = results.clickwrap_name
18+
19+
@title = @example['ExampleName']
20+
@message = format_string(@example['ResultsPageText'], results.clickwrap_name)
21+
@json = results.to_json.to_json
22+
render 'ds_common/example_done'
23+
end
24+
end
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
class Clickwrap::Ceg005ClickwrapResponsesController < EgController
2-
before_action -> { check_auth('Click') }
3-
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 5, 'Click') }
4-
5-
def create
6-
args = {
7-
account_id: session[:ds_account_id],
8-
base_path: session[:ds_base_path],
9-
access_token: session[:ds_access_token],
10-
clickwrap_id: session[:clickwrap_id],
11-
client_user_id: request[:client_user_id]
12-
}
13-
14-
results = Clickwrap::Eg005ClickwrapResponsesService.new(args).worker
15-
16-
@title = @example['ExampleName']
17-
@message = @example['ResultsPageText']
18-
@json = results.to_json.to_json
19-
render 'ds_common/example_done'
20-
end
21-
end
1+
class Clickwrap::Ceg005ClickwrapResponsesController < EgController
2+
before_action -> { check_auth('Click') }
3+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 5, 'Click') }
4+
5+
def create
6+
args = {
7+
account_id: session[:ds_account_id],
8+
base_path: session[:ds_base_path],
9+
access_token: session[:ds_access_token],
10+
clickwrap_id: session[:clickwrap_id],
11+
client_user_id: param_gsub(params[:client_user_id])
12+
}
13+
14+
results = Clickwrap::Eg005ClickwrapResponsesService.new(args).worker
15+
16+
@title = @example['ExampleName']
17+
@message = @example['ResultsPageText']
18+
@json = results.to_json.to_json
19+
render 'ds_common/example_done'
20+
end
21+
end
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
# frozen_string_literal: true
2-
3-
class ESign::Eeg032PausesSignatureWorkflowController < EgController
4-
before_action -> { check_auth('eSignature') }
5-
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 32, 'eSignature') }
6-
7-
def create
8-
signers = {
9-
signerEmail1: request['signerEmail1'],
10-
signerName1: request['signerName1'],
11-
signerEmail2: request['signerEmail2'],
12-
signerName2: request['signerName2']
13-
}
14-
args = {
15-
accountId: session['ds_account_id'],
16-
basePath: session['ds_base_path'],
17-
accessToken: session['ds_access_token'],
18-
status: 'sent'
19-
}
20-
21-
results = ESign::Eg032PausesSignatureWorkflowService.new(args, signers).worker
22-
23-
@envelop_id = results.to_hash[:envelopeId].to_s
24-
session[:envelope_id] = @envelop_id
25-
26-
render 'e_sign/eeg032_pauses_signature_workflow/return'
27-
end
28-
29-
def get
30-
enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
31-
if enableCFR == 'enabled'
32-
session[:status_cfr] = 'enabled'
33-
@title = 'Not CFR Part 11 compatible'
34-
@error_information = @manifest['SupportingTexts']['CFRError']
35-
render 'ds_common/error'
36-
end
37-
super
38-
end
39-
end
1+
# frozen_string_literal: true
2+
3+
class ESign::Eeg032PausesSignatureWorkflowController < EgController
4+
before_action -> { check_auth('eSignature') }
5+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 32, 'eSignature') }
6+
7+
def create
8+
signers = {
9+
signerEmail1: param_gsub(params['signerEmail1']),
10+
signerName1: param_gsub(params['signerName1']),
11+
signerEmail2: param_gsub(params['signerEmail2']),
12+
signerName2: param_gsub(params['signerName2'])
13+
}
14+
args = {
15+
accountId: session['ds_account_id'],
16+
basePath: session['ds_base_path'],
17+
accessToken: session['ds_access_token'],
18+
status: 'sent'
19+
}
20+
21+
results = ESign::Eg032PausesSignatureWorkflowService.new(args, signers).worker
22+
23+
@envelop_id = results.to_hash[:envelopeId].to_s
24+
session[:envelope_id] = @envelop_id
25+
26+
render 'e_sign/eeg032_pauses_signature_workflow/return'
27+
end
28+
29+
def get
30+
enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
31+
if enableCFR == 'enabled'
32+
session[:status_cfr] = 'enabled'
33+
@title = 'Not CFR Part 11 compatible'
34+
@error_information = @manifest['SupportingTexts']['CFRError']
35+
render 'ds_common/error'
36+
end
37+
super
38+
end
39+
end
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
1-
# frozen_string_literal: true
2-
3-
class ESign::Eeg034UseConditionalRecipientsController < EgController
4-
before_action -> { check_auth('eSignature') }
5-
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 34, 'eSignature') }
6-
7-
def create
8-
signers = {
9-
signerEmail1: request['signerEmail1'],
10-
signerName1: request['signerName1'],
11-
12-
signerEmailNotChecked: request['signerEmailNotChecked'],
13-
signerNameNotChecked: request['signerNameNotChecked'],
14-
15-
signerEmailChecked: request['signerEmailChecked'],
16-
signerNameChecked: request['signerNameChecked']
17-
}
18-
19-
args = {
20-
accountId: session['ds_account_id'],
21-
basePath: session['ds_base_path'],
22-
accessToken: session['ds_access_token']
23-
}
24-
25-
results = ESign::Eg034UseConditionalRecipientsService.new(args, signers).worker
26-
@envelop_id = results.to_hash[:envelopeId].to_s
27-
render 'e_sign/eeg034_use_conditional_recipients/return'
28-
rescue DocuSign_eSign::ApiError => e
29-
error = JSON.parse e.response_body
30-
@error_code = error['errorCode']
31-
if error['errorCode']['WORKFLOW_UPDATE_RECIPIENTROUTING_NOT_ALLOWED']
32-
@error_message = @example['CustomErrorTexts'][0]['ErrorMessage']
33-
@error_information = @example['CustomErrorTexts'][0]['ErrorMessage']
34-
else
35-
@error_message = error['message']
36-
end
37-
render 'ds_common/error'
38-
end
39-
40-
def get
41-
enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
42-
if enableCFR == 'enabled'
43-
session[:status_cfr] = 'enabled'
44-
@title = 'Not CFR Part 11 compatible'
45-
@error_information = @manifest['SupportingTexts']['CFRError']
46-
render 'ds_common/error'
47-
end
48-
super
49-
end
50-
end
1+
# frozen_string_literal: true
2+
3+
class ESign::Eeg034UseConditionalRecipientsController < EgController
4+
before_action -> { check_auth('eSignature') }
5+
before_action -> { @example = Utils::ManifestUtils.new.get_example(@manifest, 34, 'eSignature') }
6+
7+
def create
8+
signers = {
9+
signerEmail1: param_gsub(params['signerEmail1']),
10+
signerName1: param_gsub(params['signerName1']),
11+
12+
signerEmailNotChecked: param_gsub(params['signerEmailNotChecked']),
13+
signerNameNotChecked: param_gsub(params['signerNameNotChecked']),
14+
15+
signerEmailChecked: param_gsub(params['signerEmailChecked']),
16+
signerNameChecked: param_gsub(params['signerNameChecked'])
17+
}
18+
19+
args = {
20+
accountId: session['ds_account_id'],
21+
basePath: session['ds_base_path'],
22+
accessToken: session['ds_access_token']
23+
}
24+
25+
results = ESign::Eg034UseConditionalRecipientsService.new(args, signers).worker
26+
@envelop_id = results.to_hash[:envelopeId].to_s
27+
render 'e_sign/eeg034_use_conditional_recipients/return'
28+
rescue DocuSign_eSign::ApiError => e
29+
error = JSON.parse e.response_body
30+
@error_code = error['errorCode']
31+
if error['errorCode']['WORKFLOW_UPDATE_RECIPIENTROUTING_NOT_ALLOWED']
32+
@error_message = @example['CustomErrorTexts'][0]['ErrorMessage']
33+
@error_information = @example['CustomErrorTexts'][0]['ErrorMessage']
34+
else
35+
@error_message = error['message']
36+
end
37+
render 'ds_common/error'
38+
end
39+
40+
def get
41+
enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
42+
if enableCFR == 'enabled'
43+
session[:status_cfr] = 'enabled'
44+
@title = 'Not CFR Part 11 compatible'
45+
@error_information = @manifest['SupportingTexts']['CFRError']
46+
render 'ds_common/error'
47+
end
48+
super
49+
end
50+
end

‎app/controllers/session_controller.rb

+89-83
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,89 @@
1-
# frozen_string_literal: true
2-
3-
class SessionController < ApplicationController
4-
# GET /auth/:provider/callback
5-
def create
6-
redirect_url = if session[:eg]
7-
"/#{session[:eg]}"
8-
else
9-
root_path
10-
end
11-
12-
# reset the session
13-
internal_destroy
14-
15-
Rails.logger.debug "\n==> Docusign callback Authentication response:\n#{auth_hash.to_yaml}\n"
16-
Rails.logger.info "==> Login: New token for admin user which will expire at: #{Time.at(auth_hash.credentials['expires_at'])}"
17-
store_auth_hash_from_docusign_callback
18-
redirect_to redirect_url
19-
end
20-
21-
# GET /ds/logout
22-
def destroy
23-
internal_destroy
24-
redirect_to root_path
25-
end
26-
27-
# def switch_api
28-
# internal_destroy
29-
# end
30-
31-
# GET /auth/failure
32-
def omniauth_failure
33-
error_msg = "OmniAuth authentication failure message: #{params[:message]} for strategy: #{params[:strategy]} and HTTP_REFERER: #{params[:origin]}"
34-
Rails.logger.warn "\n==> #{error_msg}"
35-
flash[:notice] = error_msg
36-
redirect_to root_path
37-
end
38-
39-
def show
40-
Rails.logger.debug "==> Session:\n#{session.to_h.to_yaml}"
41-
render json: session.to_json
42-
end
43-
44-
protected
45-
46-
def internal_destroy
47-
session.delete :ds_expires_at
48-
session.delete :ds_user_name
49-
session.delete :ds_access_token
50-
session.delete :ds_account_id
51-
session.delete :ds_account_name
52-
session.delete :ds_base_path
53-
session.delete 'omniauth.state'
54-
session.delete 'omniauth.params'
55-
session.delete 'omniauth.origin'
56-
session.delete :envelope_id
57-
session.delete :envelope_documents
58-
session.delete :template_id
59-
session.delete :eg
60-
session.delete :manifest
61-
session.delete :status_cfr
62-
session.delete :is_workflow_published
63-
end
64-
65-
def store_auth_hash_from_docusign_callback
66-
session[:ds_expires_at] = auth_hash.credentials['expires_at']
67-
session[:ds_user_name] = auth_hash.info.name
68-
session[:ds_access_token] = auth_hash.credentials.token
69-
session[:ds_account_id] = auth_hash.extra.account_id
70-
session[:ds_account_name] = auth_hash.extra.account_name
71-
session[:ds_base_path] = auth_hash.extra.base_uri
72-
end
73-
74-
# returns hash with key structure of:
75-
# - provider
76-
# - uid
77-
# - info: [name, email, first_name, last_name]
78-
# - credentials: [token, refresh_token, expires_at, expires]
79-
# - extra: [sub, account_id, account_name, base_uri]
80-
def auth_hash
81-
@auth_hash ||= request.env['omniauth.auth']
82-
end
83-
end
1+
# frozen_string_literal: true
2+
3+
class SessionController < ApplicationController
4+
# GET /auth/:provider/callback
5+
def create
6+
redirect_url = if session[:eg]
7+
"/#{session[:eg]}"
8+
else
9+
root_path
10+
end
11+
12+
# reset the session
13+
internal_destroy
14+
15+
Rails.logger.debug "\n==> Docusign callback Authentication response:\n#{auth_hash.to_yaml}\n"
16+
Rails.logger.info "==> Login: New token for admin user which will expire at: #{Time.at(auth_hash.credentials['expires_at'])}"
17+
store_auth_hash_from_docusign_callback
18+
redirect_to redirect_url
19+
end
20+
21+
# GET /ds/logout
22+
def destroy
23+
internal_destroy
24+
redirect_to root_path
25+
end
26+
27+
# def switch_api
28+
# internal_destroy
29+
# end
30+
31+
# GET /auth/failure
32+
def omniauth_failure
33+
unless session[:pkce_failed]
34+
Rails.logger.warn "PKCE Auth failed \n"
35+
session[:pkce_failed] = true
36+
return redirect_to '/auth/docusign'
37+
end
38+
39+
error_msg = "OmniAuth authentication failure message: #{params[:message]} for strategy: #{params[:strategy]} and HTTP_REFERER: #{params[:origin]}"
40+
Rails.logger.warn "\n==> #{error_msg}"
41+
flash[:notice] = error_msg
42+
redirect_to root_path
43+
end
44+
45+
def show
46+
Rails.logger.debug "==> Session:\n#{session.to_h.to_yaml}"
47+
render json: session.to_json
48+
end
49+
50+
protected
51+
52+
def internal_destroy
53+
session.delete :ds_expires_at
54+
session.delete :ds_user_name
55+
session.delete :ds_access_token
56+
session.delete :ds_account_id
57+
session.delete :ds_account_name
58+
session.delete :ds_base_path
59+
session.delete 'omniauth.state'
60+
session.delete 'omniauth.params'
61+
session.delete 'omniauth.origin'
62+
session.delete :envelope_id
63+
session.delete :envelope_documents
64+
session.delete :template_id
65+
session.delete :eg
66+
session.delete :manifest
67+
session.delete :status_cfr
68+
session.delete :is_workflow_published
69+
end
70+
71+
def store_auth_hash_from_docusign_callback
72+
session[:ds_expires_at] = auth_hash.credentials['expires_at']
73+
session[:ds_user_name] = auth_hash.info.name
74+
session[:ds_access_token] = auth_hash.credentials.token
75+
session[:ds_account_id] = auth_hash.extra.account_id
76+
session[:ds_account_name] = auth_hash.extra.account_name
77+
session[:ds_base_path] = auth_hash.extra.base_uri
78+
end
79+
80+
# returns hash with key structure of:
81+
# - provider
82+
# - uid
83+
# - info: [name, email, first_name, last_name]
84+
# - credentials: [token, refresh_token, expires_at, expires]
85+
# - extra: [sub, account_id, account_name, base_uri]
86+
def auth_hash
87+
@auth_hash ||= request.env['omniauth.auth']
88+
end
89+
end

‎config/initializers/omniauth.rb

+61-57
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
1-
# frozen_string_literal: true
2-
3-
require 'docusign'
4-
5-
# Defaults to STDOUT: https://github.com/omniauth/omniauth#logging
6-
# Logs entries like:
7-
# (docusign) Setup endpoint detected, running now.
8-
# (docusign) Request phase initiated.
9-
# (docusign) Callback phase initiated.
10-
OmniAuth.config.logger = Rails.logger
11-
12-
# https://github.com/omniauth/omniauth/wiki/FAQ#omniauthfailureendpoint-does-not-redirect-in-development-mode
13-
# otherwise a callback exception like the following will not get caught:
14-
# OmniAuth::Strategies::OAuth2::CallbackError (access_denied)
15-
# GET "/auth/docusign/callback?error=access_denied&error_message=The%20user%20did%20not%20consent%20to%20connecting%20the%20application.&state=
16-
# OmniAuth.config.failure_raise_out_environments = [] # defaults to: ['development']
17-
18-
OmniAuth.config.allowed_request_methods = %i[post get]
19-
20-
config = Rails.application.config
21-
config.middleware.use OmniAuth::Builder do
22-
# OAuth2 login request configuration
23-
# OAuth2 login response callback message configuration is in OmniAuth::Strategies::Docusign in lib/docusign.rb
24-
provider :docusign, config.integration_key, config.integration_secret, setup: lambda { |env|
25-
strategy = env['omniauth.strategy']
26-
27-
# params = strategy.request.params
28-
# examples_API = params['examples_API']
29-
# strategy.request.params.delete('examples_API')
30-
31-
strategy.options[:client_options].site = config.app_url
32-
strategy.options[:prompt] = 'login'
33-
strategy.options[:oauth_base_uri] = config.authorization_server
34-
strategy.options[:target_account_id] = config.target_account_id
35-
strategy.options[:allow_silent_authentication] = config.allow_silent_authentication
36-
strategy.options[:client_options].authorize_url = "#{strategy.options[:oauth_base_uri]}/oauth/auth"
37-
strategy.options[:client_options].user_info_url = "#{strategy.options[:oauth_base_uri]}/oauth/userinfo"
38-
strategy.options[:client_options].token_url = "#{strategy.options[:oauth_base_uri]}/oauth/token"
39-
strategy.options[:authorize_params].prompt = strategy.options.prompt unless strategy.options[:allow_silent_authentication]
40-
session = strategy.session
41-
42-
case session[:api]
43-
when 'eSignature'
44-
strategy.options[:authorize_params].scope = 'signature'
45-
when 'Rooms'
46-
strategy.options[:authorize_params].scope = 'signature dtr.rooms.read dtr.rooms.write dtr.documents.read dtr.documents.write dtr.profile.read dtr.profile.write dtr.company.read dtr.company.write room_forms'
47-
when 'Click'
48-
strategy.options[:authorize_params].scope = 'signature click.manage click.send'
49-
when 'Admin'
50-
strategy.options[:authorize_params].scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read organization_sub_account_write organization_sub_account_read'
51-
when 'WebForms'
52-
strategy.options[:authorize_params].scope = 'signature webforms_read webforms_instance_read webforms_instance_write'
53-
when 'Maestro'
54-
strategy.options[:authorize_params].scope = 'signature aow_manage'
55-
end
56-
}
57-
end
1+
# frozen_string_literal: true
2+
3+
require 'docusign'
4+
5+
# Defaults to STDOUT: https://github.com/omniauth/omniauth#logging
6+
# Logs entries like:
7+
# (docusign) Setup endpoint detected, running now.
8+
# (docusign) Request phase initiated.
9+
# (docusign) Callback phase initiated.
10+
OmniAuth.config.logger = Rails.logger
11+
12+
# https://github.com/omniauth/omniauth/wiki/FAQ#omniauthfailureendpoint-does-not-redirect-in-development-mode
13+
# otherwise a callback exception like the following will not get caught:
14+
# OmniAuth::Strategies::OAuth2::CallbackError (access_denied)
15+
# GET "/auth/docusign/callback?error=access_denied&error_message=The%20user%20did%20not%20consent%20to%20connecting%20the%20application.&state=
16+
# OmniAuth.config.failure_raise_out_environments = [] # defaults to: ['development']
17+
18+
OmniAuth.config.allowed_request_methods = %i[post get]
19+
20+
config = Rails.application.config
21+
config.middleware.use OmniAuth::Builder do
22+
# OAuth2 login request configuration
23+
# OAuth2 login response callback message configuration is in OmniAuth::Strategies::Docusign in lib/docusign.rb
24+
provider :docusign, config.integration_key, config.integration_secret, setup: lambda { |env|
25+
strategy = env['omniauth.strategy']
26+
27+
# params = strategy.request.params
28+
# examples_API = params['examples_API']
29+
# strategy.request.params.delete('examples_API')
30+
31+
strategy.options[:client_options].site = config.app_url
32+
strategy.options[:prompt] = 'login'
33+
strategy.options[:oauth_base_uri] = config.authorization_server
34+
strategy.options[:target_account_id] = config.target_account_id
35+
strategy.options[:allow_silent_authentication] = config.allow_silent_authentication
36+
strategy.options[:client_options].authorize_url = "#{strategy.options[:oauth_base_uri]}/oauth/auth"
37+
strategy.options[:client_options].user_info_url = "#{strategy.options[:oauth_base_uri]}/oauth/userinfo"
38+
strategy.options[:client_options].token_url = "#{strategy.options[:oauth_base_uri]}/oauth/token"
39+
strategy.options[:authorize_params].prompt = strategy.options.prompt unless strategy.options[:allow_silent_authentication]
40+
session = strategy.session
41+
42+
unless session[:pkce_failed]
43+
strategy.options[:pkce] = true
44+
end
45+
46+
case session[:api]
47+
when 'eSignature'
48+
strategy.options[:authorize_params].scope = 'signature'
49+
when 'Rooms'
50+
strategy.options[:authorize_params].scope = 'signature dtr.rooms.read dtr.rooms.write dtr.documents.read dtr.documents.write dtr.profile.read dtr.profile.write dtr.company.read dtr.company.write room_forms'
51+
when 'Click'
52+
strategy.options[:authorize_params].scope = 'signature click.manage click.send'
53+
when 'Admin'
54+
strategy.options[:authorize_params].scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read organization_sub_account_write organization_sub_account_read'
55+
when 'WebForms'
56+
strategy.options[:authorize_params].scope = 'signature webforms_read webforms_instance_read webforms_instance_write'
57+
when 'Maestro'
58+
strategy.options[:authorize_params].scope = 'signature aow_manage'
59+
end
60+
}
61+
end

‎quick_acg/app/controllers/ds_common_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def handle_redirects
1212
session[:quickstarted] = true
1313
redirect_to '/auth/docusign'
1414
else
15+
return redirect_to '/auth/docusign' if session[:ds_access_token].nil? || session[:ds_base_path].nil?
16+
1517
enableCFR = ESign::GetDataService.new(session[:ds_access_token], session[:ds_base_path]).cfr?(session[:ds_account_id])
1618
if enableCFR == 'enabled'
1719
session[:status_cfr] = 'enabled'
+55-51
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,55 @@
1-
# frozen_string_literal: true
2-
3-
require 'docusign'
4-
5-
# Defaults to STDOUT: https://github.com/omniauth/omniauth#logging
6-
# Logs entries like:
7-
# (docusign) Setup endpoint detected, running now.
8-
# (docusign) Request phase initiated.
9-
# (docusign) Callback phase initiated.
10-
OmniAuth.config.logger = Rails.logger
11-
12-
# https://github.com/omniauth/omniauth/wiki/FAQ#omniauthfailureendpoint-does-not-redirect-in-development-mode
13-
# otherwise a callback exception like the following will not get caught:
14-
# OmniAuth::Strategies::OAuth2::CallbackError (access_denied)
15-
# GET "/auth/docusign/callback?error=access_denied&error_message=The%20user%20did%20not%20consent%20to%20connecting%20the%20application.&state=
16-
# OmniAuth.config.failure_raise_out_environments = [] # defaults to: ['development']
17-
18-
OmniAuth.config.allowed_request_methods = %i[post get]
19-
20-
config = Rails.application.config
21-
config.middleware.use OmniAuth::Builder do
22-
# OAuth2 login request configuration
23-
# OAuth2 login response callback message configuration is in OmniAuth::Strategies::Docusign in lib/docusign.rb
24-
provider :docusign, config.integration_key, config.integration_secret, setup: lambda { |env|
25-
strategy = env['omniauth.strategy']
26-
27-
# params = strategy.request.params
28-
# examples_API = params['examples_API']
29-
# strategy.request.params.delete('examples_API')
30-
31-
strategy.options[:client_options].site = config.app_url
32-
strategy.options[:prompt] = 'login'
33-
strategy.options[:oauth_base_uri] = config.authorization_server
34-
strategy.options[:target_account_id] = config.target_account_id
35-
strategy.options[:allow_silent_authentication] = config.allow_silent_authentication
36-
strategy.options[:client_options].authorize_url = "#{strategy.options[:oauth_base_uri]}/oauth/auth"
37-
strategy.options[:client_options].user_info_url = "#{strategy.options[:oauth_base_uri]}/oauth/userinfo"
38-
strategy.options[:client_options].token_url = "#{strategy.options[:oauth_base_uri]}/oauth/token"
39-
strategy.options[:authorize_params].prompt = strategy.options.prompt unless strategy.options[:allow_silent_authentication]
40-
session = strategy.session
41-
42-
case session[:api]
43-
when 'Rooms'
44-
strategy.options[:authorize_params].scope = 'signature dtr.rooms.read dtr.rooms.write dtr.documents.read dtr.documents.write dtr.profile.read dtr.profile.write dtr.company.read dtr.company.write room_forms'
45-
when 'Click'
46-
strategy.options[:authorize_params].scope = 'signature click.manage click.send'
47-
when 'Admin'
48-
strategy.options[:authorize_params].scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read'
49-
end
50-
}
51-
end
1+
# frozen_string_literal: true
2+
3+
require 'docusign'
4+
5+
# Defaults to STDOUT: https://github.com/omniauth/omniauth#logging
6+
# Logs entries like:
7+
# (docusign) Setup endpoint detected, running now.
8+
# (docusign) Request phase initiated.
9+
# (docusign) Callback phase initiated.
10+
OmniAuth.config.logger = Rails.logger
11+
12+
# https://github.com/omniauth/omniauth/wiki/FAQ#omniauthfailureendpoint-does-not-redirect-in-development-mode
13+
# otherwise a callback exception like the following will not get caught:
14+
# OmniAuth::Strategies::OAuth2::CallbackError (access_denied)
15+
# GET "/auth/docusign/callback?error=access_denied&error_message=The%20user%20did%20not%20consent%20to%20connecting%20the%20application.&state=
16+
OmniAuth.config.failure_raise_out_environments = [] # defaults to: ['development']
17+
18+
OmniAuth.config.allowed_request_methods = %i[post get]
19+
20+
config = Rails.application.config
21+
config.middleware.use OmniAuth::Builder do
22+
# OAuth2 login request configuration
23+
# OAuth2 login response callback message configuration is in OmniAuth::Strategies::Docusign in lib/docusign.rb
24+
provider :docusign, config.integration_key, config.integration_secret, setup: lambda { |env|
25+
strategy = env['omniauth.strategy']
26+
27+
# params = strategy.request.params
28+
# examples_API = params['examples_API']
29+
# strategy.request.params.delete('examples_API')
30+
31+
strategy.options[:client_options].site = config.app_url
32+
strategy.options[:prompt] = 'login'
33+
strategy.options[:oauth_base_uri] = config.authorization_server
34+
strategy.options[:target_account_id] = config.target_account_id
35+
strategy.options[:allow_silent_authentication] = config.allow_silent_authentication
36+
strategy.options[:client_options].authorize_url = "#{strategy.options[:oauth_base_uri]}/oauth/auth"
37+
strategy.options[:client_options].user_info_url = "#{strategy.options[:oauth_base_uri]}/oauth/userinfo"
38+
strategy.options[:client_options].token_url = "#{strategy.options[:oauth_base_uri]}/oauth/token"
39+
strategy.options[:authorize_params].prompt = strategy.options.prompt unless strategy.options[:allow_silent_authentication]
40+
session = strategy.session
41+
42+
unless session[:pkce_failed]
43+
strategy.options[:pkce] = true
44+
end
45+
46+
case session[:api]
47+
when 'Rooms'
48+
strategy.options[:authorize_params].scope = 'signature dtr.rooms.read dtr.rooms.write dtr.documents.read dtr.documents.write dtr.profile.read dtr.profile.write dtr.company.read dtr.company.write room_forms'
49+
when 'Click'
50+
strategy.options[:authorize_params].scope = 'signature click.manage click.send'
51+
when 'Admin'
52+
strategy.options[:authorize_params].scope = 'signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read user_data_redact asset_group_account_read asset_group_account_clone_write asset_group_account_clone_read'
53+
end
54+
}
55+
end

‎quick_acg/config/routes.rb

+43-40
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
1-
require_relative '../../app/controllers/application_controller'
2-
require_relative '../../app/controllers/eg_controller'
3-
require_relative '../../app/controllers/session_controller'
4-
require_relative '../../app/services/api_creator'
5-
require_relative '../../app/controllers/eeg001_embedded_signing_controller'
6-
require_relative '../../app/services/eg001_embedded_signing_service'
7-
require_relative '../../app/services/utils'
8-
9-
class ESign
10-
end
11-
12-
require_relative '../../app/controllers/e_sign/eeg041_cfr_embedded_signing_controller'
13-
require_relative '../../app/services/e_sign/eg041_cfr_embedded_signing_service'
14-
require_relative '../../app/services/e_sign/get_data_service'
15-
16-
Rails.application.routes.draw do
17-
root 'ds_common#index'
18-
19-
get '/eeg001' => 'eeg001_embedded_signing#get'
20-
post '/eeg001' => 'eeg001_embedded_signing#create'
21-
22-
scope module: 'e_sign' do
23-
get 'eeg041' => 'eeg041_cfr_embedded_signing#get'
24-
post 'eeg041' => 'eeg041_cfr_embedded_signing#create'
25-
end
26-
# Login starts with POST'ing to: /auth/docusign
27-
# /auth/docusign is an internal route created by OmniAuth and the docusign strategy from: /lib/docusign.rb
28-
# Should be POST, see: https://nvd.nist.gov/vuln/detail/CVE-2015-9284
29-
# get '/ds/login' => redirect('/auth/docusign')
30-
31-
# Handle OmniAuth OAuth2 login callback result that includes the AuthHash
32-
get '/auth/:provider/callback', to: 'session#create'
33-
34-
get '/ds_common-return' => 'ds_common#index'
35-
36-
get '/ds/mustAuthenticate' => 'ds_common#ds_must_authenticate'
37-
post '/ds/mustAuthenticate' => 'ds_common#ds_must_authenticate'
38-
39-
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
40-
end
1+
require_relative '../../app/controllers/application_controller'
2+
require_relative '../../app/controllers/eg_controller'
3+
require_relative '../../app/controllers/session_controller'
4+
require_relative '../../app/services/api_creator'
5+
require_relative '../../app/controllers/eeg001_embedded_signing_controller'
6+
require_relative '../../app/services/eg001_embedded_signing_service'
7+
require_relative '../../app/services/utils'
8+
9+
class ESign
10+
end
11+
12+
require_relative '../../app/controllers/e_sign/eeg041_cfr_embedded_signing_controller'
13+
require_relative '../../app/services/e_sign/eg041_cfr_embedded_signing_service'
14+
require_relative '../../app/services/e_sign/get_data_service'
15+
16+
Rails.application.routes.draw do
17+
root 'ds_common#index'
18+
19+
get '/eeg001' => 'eeg001_embedded_signing#get'
20+
post '/eeg001' => 'eeg001_embedded_signing#create'
21+
22+
scope module: 'e_sign' do
23+
get 'eeg041' => 'eeg041_cfr_embedded_signing#get'
24+
post 'eeg041' => 'eeg041_cfr_embedded_signing#create'
25+
end
26+
# Login starts with POST'ing to: /auth/docusign
27+
# /auth/docusign is an internal route created by OmniAuth and the docusign strategy from: /lib/docusign.rb
28+
# Should be POST, see: https://nvd.nist.gov/vuln/detail/CVE-2015-9284
29+
# get '/ds/login' => redirect('/auth/docusign')
30+
31+
# Handle OmniAuth OAuth2 login callback result that includes the AuthHash
32+
get '/auth/:provider/callback', to: 'session#create'
33+
34+
# Handle OmniAuth OAuth2 login exceptions
35+
get '/auth/failure', to: 'session#omniauth_failure'
36+
37+
get '/ds_common-return' => 'ds_common#index'
38+
39+
get '/ds/mustAuthenticate' => 'ds_common#ds_must_authenticate'
40+
post '/ds/mustAuthenticate' => 'ds_common#ds_must_authenticate'
41+
42+
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
43+
end

0 commit comments

Comments
 (0)
Please sign in to comment.