Skip to content

Commit 47107f1

Browse files
authored
Merge pull request docusign#37 from docusign/DEVDOCS-5747
API drop down menu
2 parents 1e6ca12 + 588cbbd commit 47107f1

23 files changed

Lines changed: 348 additions & 41 deletions

app/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
22

3-
from flask import Flask
3+
from flask import Flask, session
44
from flask_wtf.csrf import CSRFProtect
55

66
from .ds_config import DS_CONFIG
77
from .eSignature import examples
88
from .docusign.views import ds
9-
from .ds_config import EXAMPLES_API_TYPE
9+
from .api_type import EXAMPLES_API_TYPE
1010
from .rooms import examples as rooms_examples
1111
from .click import examples as click_examples
1212
from .monitor import examples as monitor_examples

app/admin/templates/base.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
data-busy="href">Login <span class="sr-only">(current)</span></a>
3838
</li>
3939
{% endif %}
40+
<li class="nav-item active">
41+
<a class="nav-link" href="{{ url_for('ds.choose_api') }}">Choose API <span class="sr-only">(current)</span></a>
42+
</li>
4043
</ul>
4144

4245
{% if session['ds_user_name'] %}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!-- extend base layout -->
2+
{% extends "base.html" %}
3+
4+
{% block content %}
5+
<div style="margin:1% 5%;">
6+
<h1 class="display-4">Please Choose an API</h1>
7+
8+
<form method="post" data-busy="form" action={{ url_for("ds.api_selected") }}>
9+
<div class="form-group col-md-5">
10+
<label for="chosen_api">Please choose your API</label>
11+
<select class="form-control" id="chosen_api" name="chosen_api">
12+
<option value="ESignature">eSignature</option>
13+
<option value="Rooms">Rooms</option>
14+
<option value="Click">Click</option>
15+
<option value="Monitor">Monitor</option>
16+
<option value="Admin">Admin</option>
17+
</select>
18+
<p class="lead" style="padding-top: .5rem;">
19+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
20+
<button type="submit" class="btn btn-docu">Choose your desired API</button>
21+
</p>
22+
</div>
23+
</form>
24+
<hr class="my-4">
25+
</div>
26+
{% endblock %}

app/admin/templates/must_authenticate.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,29 @@
22
{% extends "base.html" %}
33

44
{% block content %}
5+
{% if chosen_api == "Monitor" %}
6+
<div style="margin:1% 5%;">
7+
<h1 class="display-4">Please Authenticate with DocuSign</h1>
8+
9+
<form method="post" data-busy="form" action={{ url_for("ds.ds_login") }}>
10+
<div class="form-group col-md-5">
11+
<label for="auth_type">Please choose your OAuth2.0 grant type</label>
12+
<select class="form-control" id="auth_type" name="auth_type">
13+
<option value="jwt">JSON Web Token</option>
14+
</select>
15+
<p class="lead" style="padding-top: .5rem;">
16+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
17+
<button type="submit" class="btn btn-docu">Authenticate with DocuSign</button>
18+
</p>
19+
</div>
20+
</form>
21+
<hr class="my-4">
22+
</div>
23+
24+
{% else %}
25+
526
<div style="margin:1% 5%;">
6-
<h1 class="display-4">Please authenticate with DocuSign</h1>
27+
<h1 class="display-4">Please Authenticate with DocuSign</h1>
728

829
<form method="post" data-busy="form" action={{ url_for("ds.ds_login") }}>
930
<div class="form-group col-md-5">
@@ -19,6 +40,6 @@ <h1 class="display-4">Please authenticate with DocuSign</h1>
1940
</div>
2041
</form>
2142
<hr class="my-4">
22-
<p>You need to authenticate with DocuSign to continue your request.</p>
2343
</div>
44+
{% endif %}
2445
{% endblock %}

app/api_type.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EXAMPLES_API_TYPE ={'Rooms': False, 'ESignature': True, 'Click': False, 'Monitor': False, 'Admin': False}

app/click/templates/base.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
data-busy="href">Login <span class="sr-only">(current)</span></a>
3838
</li>
3939
{% endif %}
40+
<li class="nav-item active">
41+
<a class="nav-link" href="{{ url_for('ds.choose_api') }}">Choose API <span class="sr-only">(current)</span></a>
42+
</li>
4043
</ul>
4144

4245
{% if session['ds_user_name'] %}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!-- extend base layout -->
2+
{% extends "base.html" %}
3+
4+
{% block content %}
5+
<div style="margin:1% 5%;">
6+
<h1 class="display-4">Please Choose an API</h1>
7+
8+
<form method="post" data-busy="form" action={{ url_for("ds.api_selected") }}>
9+
<div class="form-group col-md-5">
10+
<label for="chosen_api">Please choose your API</label>
11+
<select class="form-control" id="chosen_api" name="chosen_api">
12+
<option value="ESignature">eSignature</option>
13+
<option value="Rooms">Rooms</option>
14+
<option value="Click">Click</option>
15+
<option value="Monitor">Monitor</option>
16+
<option value="Admin">Admin</option>
17+
</select>
18+
<p class="lead" style="padding-top: .5rem;">
19+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
20+
<button type="submit" class="btn btn-docu">Choose your desired API</button>
21+
</p>
22+
</div>
23+
</form>
24+
<hr class="my-4">
25+
</div>
26+
{% endblock %}

app/click/templates/must_authenticate.html

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,29 @@
22
{% extends "base.html" %}
33

44
{% block content %}
5+
{% if chosen_api == "Monitor" %}
6+
<div style="margin:1% 5%;">
7+
<h1 class="display-4">Please Authenticate with DocuSign</h1>
8+
9+
<form method="post" data-busy="form" action={{ url_for("ds.ds_login") }}>
10+
<div class="form-group col-md-5">
11+
<label for="auth_type">Please choose your OAuth2.0 grant type</label>
12+
<select class="form-control" id="auth_type" name="auth_type">
13+
<option value="jwt">JSON Web Token</option>
14+
</select>
15+
<p class="lead" style="padding-top: .5rem;">
16+
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
17+
<button type="submit" class="btn btn-docu">Authenticate with DocuSign</button>
18+
</p>
19+
</div>
20+
</form>
21+
<hr class="my-4">
22+
</div>
23+
24+
{% else %}
25+
526
<div style="margin:1% 5%;">
6-
<h1 class="display-4">Please authenticate with DocuSign</h1>
27+
<h1 class="display-4">Please Authenticate with DocuSign</h1>
728

829
<form method="post" data-busy="form" action={{ url_for("ds.ds_login") }}>
930
<div class="form-group col-md-5">
@@ -19,6 +40,6 @@ <h1 class="display-4">Please authenticate with DocuSign</h1>
1940
</div>
2041
</form>
2142
<hr class="my-4">
22-
<p>You need to authenticate with DocuSign to continue your request.</p>
2343
</div>
44+
{% endif %}
2445
{% endblock %}

app/docusign/ds_client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44

55
import requests
6-
from flask import current_app as app, url_for, redirect, render_template, request
6+
from flask import current_app as app, url_for, redirect, render_template, request, session
77
from flask_oauthlib.client import OAuth
88
from docusign_esign import ApiClient
99
from docusign_esign.client.api_exception import ApiException
1010

11-
from ..ds_config import DS_CONFIG, DS_JWT, EXAMPLES_API_TYPE
11+
from ..ds_config import DS_CONFIG, DS_JWT
12+
from ..api_type import EXAMPLES_API_TYPE
1213
from ..error_handlers import process_error
1314

1415
SCOPES = [
@@ -103,10 +104,9 @@ def _jwt_auth(cls):
103104
user_id=DS_JWT["ds_impersonated_user_id"],
104105
oauth_host_name=DS_JWT["authorization_server"],
105106
private_key_bytes=private_key,
106-
expires_in=3600,
107+
expires_in=4000,
107108
scopes=use_scopes
108109
)
109-
110110
return redirect(url_for("ds.ds_callback"))
111111

112112
except ApiException as err:
@@ -122,6 +122,10 @@ def _jwt_auth(cls):
122122
else:
123123
process_error(err)
124124

125+
return redirect(url_for("ds.ds_callback"))
126+
127+
128+
125129
@classmethod
126130
def destroy(cls):
127131
cls.ds_app = None

app/docusign/views.py

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
from flask import redirect, request, url_for, flash, render_template, Blueprint, session, current_app as app
44

5+
import json
56
from .ds_client import DSClient
67
from .utils import ds_logout_internal
78
from ..consts import base_uri_suffix
89
from ..ds_config import DS_CONFIG
9-
from ..ds_config import EXAMPLES_API_TYPE
10+
from ..api_type import EXAMPLES_API_TYPE
1011

1112
ds = Blueprint("ds", __name__, url_prefix="/ds")
1213

@@ -28,6 +29,44 @@ def ds_logout():
2829
app.config["quickstart"] = False
2930
return redirect(url_for("core.index"))
3031

32+
@ds.route("/choose_api")
33+
def choose_api():
34+
return render_template("choose_api.html", title="Choose API")
35+
36+
@ds.route("/api_selected", methods=["GET", "POST"])
37+
def api_selected():
38+
chosen_api = request.form.get("chosen_api")
39+
40+
new_api_type = EXAMPLES_API_TYPE
41+
42+
# Set all values to False
43+
for api_type in new_api_type:
44+
if new_api_type[api_type] == True:
45+
new_api_type[api_type] = False
46+
47+
# Update the new chosen API type to True
48+
if chosen_api == "ESignature":
49+
new_api_type["ESignature"] = True
50+
elif chosen_api == "Rooms":
51+
new_api_type["Rooms"] = True
52+
elif chosen_api == "Admin":
53+
new_api_type["Admin"] = True
54+
elif chosen_api == "Monitor":
55+
new_api_type["Monitor"] = True
56+
elif chosen_api == "Click":
57+
new_api_type["Click"] = True
58+
59+
# Overwrite api_type.py file
60+
with open("app/api_type.py", "w") as api_type_file:
61+
api_type_file.write("EXAMPLES_API_TYPE =" + str(new_api_type))
62+
63+
ds_logout_internal()
64+
flash("You have logged out from DocuSign.")
65+
app.config["isLoggedIn"] = False
66+
app.config["quickstart"] = False
67+
68+
return render_template("must_authenticate.html", title="Must authenticate", chosen_api=chosen_api)
69+
3170

3271
@ds.route("/callback")
3372
def ds_callback():
@@ -77,7 +116,7 @@ def ds_callback():
77116

78117
@ds.route("/must_authenticate")
79118
def ds_must_authenticate():
80-
if DS_CONFIG["quickstart"] == "true" and EXAMPLES_API_TYPE['ESignature']:
119+
if DS_CONFIG["quickstart"] == "true" and EXAMPLES_API_TYPE["ESignature"]:
81120
session["auth_type"] = "code_grant"
82121
return redirect(url_for("ds.ds_login"))
83122

0 commit comments

Comments
 (0)