Skip to content

Commit 05e0338

Browse files
Devdocs 5748 (#49)
* add step admin4 step 4 and update text * working changes to dropdown api * update config file * routing constraints * update routes * update Gemfile * remove debug statements * updates to dropdown * update routes * remove export data * Revert "update routes" This reverts commit 4b680a53f0e088fa34a16086183ad8827fb97de7. * Revert "remove export data" This reverts commit 4d05ab7a6a3fb2e55969be5992f901e4dd60141c. * update routes and remove data * include banner when logged in * include default session api type * small quickstart related fix * fix jwt issue
1 parent d0e203b commit 05e0338

File tree

13 files changed

+118
-74
lines changed

13 files changed

+118
-74
lines changed

Gemfile.lock

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ GEM
9797
json (~> 2.1, >= 2.1.0)
9898
jwt (~> 2.2, >= 2.2.1)
9999
typhoeus (~> 1.0, >= 1.0.1)
100-
docusign_esign (3.13.0.rc1)
100+
docusign_esign (3.13.0)
101101
addressable (~> 2.7, >= 2.7.0)
102102
json (~> 2.1, >= 2.1.0)
103103
jwt (~> 2.2, >= 2.2.1)
@@ -113,10 +113,10 @@ GEM
113113
jwt (~> 2.2, >= 2.2.1)
114114
typhoeus (~> 1.0, >= 1.0.1)
115115
erubi (1.10.0)
116-
ethon (0.14.0)
116+
ethon (0.15.0)
117117
ffi (>= 1.15.0)
118118
execjs (2.8.1)
119-
faraday (1.7.0)
119+
faraday (1.8.0)
120120
faraday-em_http (~> 1.0)
121121
faraday-em_synchrony (~> 1.0)
122122
faraday-excon (~> 1.1)
@@ -135,17 +135,17 @@ GEM
135135
faraday-net_http_persistent (1.2.0)
136136
faraday-patron (1.0.0)
137137
faraday-rack (1.0.0)
138-
ffi (1.15.3)
138+
ffi (1.15.4)
139139
globalid (0.5.2)
140140
activesupport (>= 5.0)
141141
hashie (4.1.0)
142-
i18n (1.8.10)
142+
i18n (1.8.11)
143143
concurrent-ruby (~> 1.0)
144144
io-like (0.3.1)
145145
jbuilder (2.10.2)
146146
activesupport (>= 5.0.0)
147-
json (2.5.1)
148-
jwt (2.2.3)
147+
json (2.6.1)
148+
jwt (2.3.0)
149149
listen (3.2.1)
150150
rb-fsevent (~> 0.10, >= 0.10.3)
151151
rb-inotify (~> 0.9, >= 0.9.10)
@@ -154,9 +154,9 @@ GEM
154154
nokogiri (>= 1.5.9)
155155
mail (2.7.1)
156156
mini_mime (>= 0.1.1)
157-
marcel (1.0.1)
157+
marcel (1.0.2)
158158
method_source (0.9.2)
159-
mini_mime (1.1.1)
159+
mini_mime (1.1.2)
160160
minitest (5.14.4)
161161
msgpack (1.4.2)
162162
multi_json (1.15.0)
@@ -177,7 +177,7 @@ GEM
177177
hashie (>= 3.4.6)
178178
rack (>= 1.6.2, < 3)
179179
rack-protection
180-
omniauth-oauth2 (1.7.1)
180+
omniauth-oauth2 (1.7.2)
181181
oauth2 (~> 1.4)
182182
omniauth (>= 1.9, < 3)
183183
omniauth-rails_csrf_protection (1.0.0)
@@ -191,9 +191,9 @@ GEM
191191
pry-rails (0.3.9)
192192
pry (>= 0.10.4)
193193
public_suffix (4.0.6)
194-
puma (4.3.9)
194+
puma (4.3.10)
195195
nio4r (~> 2.0)
196-
racc (1.5.2)
196+
racc (1.6.0)
197197
rack (2.2.3)
198198
rack-protection (2.1.0)
199199
rack
@@ -279,7 +279,7 @@ GEM
279279
websocket-extensions (0.1.5)
280280
xpath (3.2.0)
281281
nokogiri (~> 1.8)
282-
zeitwerk (2.4.2)
282+
zeitwerk (2.5.1)
283283

284284
PLATFORMS
285285
x86_64-darwin-20

app/controllers/ds_common_controller.rb

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,33 @@ class DsCommonController < ApplicationController
66

77
def index
88
@show_doc = Rails.application.config.documentation
9-
if Rails.configuration.examples_API['Rooms']
9+
if session[:examples_API] == 'Rooms'
1010
render 'room_api/index'
11-
elsif Rails.configuration.examples_API['Click']
11+
elsif session[:examples_API] == 'Click'
1212
render 'clickwrap/index'
13-
elsif Rails.configuration.examples_API['Monitor']
13+
elsif session[:examples_API] == 'Monitor'
1414
render 'monitor_api/index'
15-
elsif Rails.configuration.examples_API['Admin']
15+
elsif session[:examples_API] == 'Admin'
1616
render 'admin_api/index'
1717
else
18+
session[:examples_API] = 'eSignature'
1819
@show_doc = Rails.application.config.documentation
1920
if Rails.configuration.quickstart && session[:been_here].nil?
2021
redirect_to '/eg001'
2122
end
2223
end
2324
end
2425

26+
def choose_api
27+
render 'ds_common/choose_api'
28+
end
29+
30+
def api_selected
31+
session.delete :eg
32+
session[:examples_API] = params[:chosen_api]
33+
redirect_to '/ds/mustAuthenticate'
34+
end
35+
2536
def ds_return
2637
# To break out of the Quickstart loop an example has been completed
2738
session[:been_here] = true
@@ -32,17 +43,17 @@ def ds_return
3243
end
3344

3445
def ds_must_authenticate
35-
if Rails.configuration.examples_API['Monitor']
46+
if session[:examples_API] == 'Monitor'
3647
jwt_auth
3748
end
38-
if Rails.configuration.quickstart
39-
redirect_to('/auth/docusign')
49+
if Rails.configuration.quickstart and session[:been_here].nil? and session[:examples_API] == 'eSignature'
50+
redirect_to "/auth/docusign"
4051
end
4152
@title = 'Authenticate with DocuSign'
4253
@show_doc = Rails.application.config.documentation
4354

4455
if params[:auth] == 'grand-auth'
45-
redirect_to('/auth/docusign')
56+
redirect_to "/auth/docusign"
4657
elsif params[:auth] == 'jwt-auth'
4758
jwt_auth
4859
end
@@ -57,16 +68,16 @@ def jwt_auth
5768
end
5869
else
5970
session['omniauth.state'] = SecureRandom.hex
60-
url = JwtAuth::JwtCreator.consent_url(session['omniauth.state'])
71+
url = JwtAuth::JwtCreator.consent_url(session['omniauth.state'], session['examples_API'])
6172
redirect_to root_path if session[:token].present?
6273
end
63-
if Rails.configuration.examples_API['Rooms']
74+
if session[:examples_API] == 'Rooms'
6475
configuration = DocuSign_Rooms::Configuration.new
6576
api_client = DocuSign_Rooms::ApiClient.new(configuration)
66-
elsif Rails.configuration.examples_API['Click']
77+
elsif session[:examples_API] == 'Click'
6778
configuration = DocuSign_Click::Configuration.new
6879
api_client = DocuSign_Click::ApiClient.new configuration
69-
elsif Rails.configuration.examples_API['Admin']
80+
elsif session[:examples_API] == 'Admin'
7081
configuration = DocuSign_Admin::Configuration.new
7182
api_client = DocuSign_Admin::ApiClient.new configuration
7283
end

app/controllers/session_controller.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ def destroy
2424
redirect_to root_path
2525
end
2626

27+
# def switch_api
28+
# internal_destroy
29+
# end
30+
2731
# GET /auth/failure
2832
def omniauth_failure
2933
error_msg = "OmniAuth authentication failure message: #{params[:message]} for strategy: #{params[:strategy]} and HTTP_REFERER: #{params[:origin]}"

app/services/admin_api/get_data_service.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ def get_ds_groups
3232

3333
def get_organization_id
3434
worker
35-
puts "\n\n getting org_id \n\n"
3635
accounts_api = DocuSign_Admin::AccountsApi.new(@api_client)
3736
accounts_api.get_organizations().organizations[0].as_json['id']
3837
end

app/services/jwt_auth/jwt_creator.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ class JwtCreator
99
# DocuSign authorization URI to obtain individual consent
1010
# https://developers.docusign.com/platform/auth/jwt/jwt-get-token
1111
# https://developers.docusign.com/platform/auth/consent/obtaining-individual-consent/
12-
def self.consent_url(state)
12+
def self.consent_url(state, examples_API)
1313
# GET /oauth/auth
1414
# This endpoint is used to obtain consent and is the first step in several authentication flows.
1515
# https://developers.docusign.com/platform/auth/reference/obtain-consent
1616
scope = "signature"
17-
if Rails.configuration.examples_API['Rooms']
17+
if examples_API == 'Rooms'
1818
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"
19-
elsif Rails.configuration.examples_API['Click']
19+
elsif examples_API == 'Click'
2020
scope = "signature click.manage click.send"
21-
elsif Rails.configuration.examples_API['Admin']
21+
elsif examples_API == 'Admin'
2222
scope = "signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read"
2323
end
2424
scope = "#{scope} impersonation"
@@ -36,15 +36,15 @@ def initialize(session)
3636
@session = session
3737
scope = "signature"
3838
@client_module = DocuSign_eSign
39-
if Rails.configuration.examples_API['Rooms']
39+
if session[:examples_API] == 'Rooms'
4040
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"
4141
@client_module = DocuSign_Rooms
42-
elsif Rails.configuration.examples_API['Click']
42+
elsif session[:examples_API] == 'Click'
4343
scope = "signature click.manage click.send"
4444
@client_module = DocuSign_Click
45-
elsif Rails.configuration.examples_API['Monitor']
45+
elsif session[:examples_API] == 'Monitor'
4646
@client_module = DocuSign_Monitor
47-
elsif Rails.configuration.examples_API['Admin']
47+
elsif session[:examples_API] == 'Admin'
4848
scope = "signature organization_read group_read permission_read user_read user_write account_read domain_read identity_provider_read"
4949
@client_module = DocuSign_Admin
5050
end
@@ -69,6 +69,11 @@ def check_jwt_token
6969
end
7070
rescue @client_module::ApiError => exception
7171
Rails.logger.warn exception.inspect
72+
73+
if exception.response_body == nil
74+
return false
75+
end
76+
7277
body = JSON.parse(exception.response_body)
7378

7479
if body['error'] == "consent_required"

app/views/clickwrap/index.html.erb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<% if !session[:ds_user_name] %>
2-
<!-- IF not signed in -->
1+
32
<div class="container-fill-bg header-div">
43
<div class="jumbotron jumbotron-fluid">
54
<table>
@@ -18,7 +17,6 @@
1817
</div>
1918

2019
</div>
21-
<% end %>
2220

2321
<div class="container body-div" id="index-page">
2422
<h2>Welcome</h2>

app/views/ds_common/choose_api.erb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<div style="margin:1% 5%;">
2+
<h1 class="display-4">Please Choose an API</h1>
3+
<p class="lead">
4+
<form class="eg" action="/ds/apiSelected" method="POST" data-busy="form">
5+
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
6+
<div class="form-group">
7+
<select id="chosen_api" name="chosen_api" class="form-control">
8+
<option value="eSignature" selected>eSignature</option>
9+
<option value="Rooms">Rooms</option>
10+
<option value="Click">Click</option>
11+
<option value="Monitor">Monitor</option>
12+
<option value="Admin">Admin</option>
13+
</select><br>
14+
<button class="btn btn-docu btn-lg">Choose your desired API</button>
15+
</div>
16+
</form>
17+
</p>
18+
<hr class="my-4">
19+
</div>

app/views/ds_common/ds_must_authenticate.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
66
<div class="form-group">
77
<select id="auth" name="auth" class="form-control">
8-
<% unless Rails.configuration.examples_API['Monitor'] %>
8+
<% unless session[:examples_API] == 'Monitor' %>
99
<option value="grand-auth" selected>Authorization Code grant</option>
1010
<% end %>
1111
<option value="jwt-auth">JSON Web Token (JWT) grant</option>

app/views/layouts/_head.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
<a class="nav-link" href="/ds/mustAuthenticate">Login <span class="sr-only">(current)</span></a>
4646
</li>
4747
<% end %>
48+
<li class="nav-item active">
49+
<a class="nav-link" href="/ds/chooseApi">Choose API <span class="sr-only">(current)</span></a>
50+
</li>
4851
</ul>
4952

5053
<% if session["ds_user_name"] %>
@@ -82,4 +85,3 @@
8285
<section id="content" class="container-full-bg">
8386
<% end %>
8487
<% end %>
85-

app/views/room_api/index.html.erb

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
<% if !session[:ds_user_name] %>
2-
<!-- IF not signed in -->
3-
<div class="container-fill-bg header-div">
4-
<div class="jumbotron jumbotron-fluid">
5-
<table>
6-
<tbody>
7-
<tr>
8-
<td>
9-
<h1 class="display-4">Ruby Launcher</h1>
10-
<p class="Xlead">Welcome to the DocuSign Ruby examples using multiple OAuth flows (JWT and Authorization
11-
Code Grant).</p>
12-
</td>
13-
<td>
14-
<img src="banner-code.png"/>
15-
</td>
16-
</tr>
17-
</tbody>
18-
</table>
19-
</div>
1+
2+
<div class="container-fill-bg header-div">
3+
<div class="jumbotron jumbotron-fluid">
4+
<table>
5+
<tbody>
6+
<tr>
7+
<td>
8+
<h1 class="display-4">Ruby Launcher</h1>
9+
<p class="Xlead">Welcome to the DocuSign Ruby examples using multiple OAuth flows (JWT and Authorization
10+
Code Grant).</p>
11+
</td>
12+
<td>
13+
<img src="banner-code.png"/>
14+
</td>
15+
</tr>
16+
</tbody>
17+
</table>
2018
</div>
21-
<% end %>
19+
</div>
2220

2321
<div class="container body-div" id="index-page">
2422
<h2>Welcome</h2>

0 commit comments

Comments
 (0)