Skip to content

Commit 88d8b4e

Browse files
committed
updates to phone authentication example
1 parent 85576be commit 88d8b4e

11 files changed

Lines changed: 240 additions & 154 deletions

File tree

app/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
app.register_blueprint(examples.eg018)
9292
app.register_blueprint(examples.eg019)
9393
app.register_blueprint(examples.eg020)
94-
app.register_blueprint(examples.eg021)
9594
app.register_blueprint(examples.eg022)
9695
app.register_blueprint(examples.eg023)
9796
app.register_blueprint(examples.eg024)

app/eSignature/examples/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from .eg017_set_template_tab_values import eg017
1818
from .eg018_envelope_custom_field_data import eg018
1919
from .eg019_access_code_authentication import eg019
20-
from .eg020_sms_authentication import eg020
21-
from .eg021_phone_authentication import eg021
20+
from .eg020_phone_authentication import eg020
2221
from .eg022_kba_authentication import eg022
2322
from .eg023_idv_authentication import eg023
2423
from .eg024_permissions_creating import eg024

app/eSignature/examples/eg020_sms_authentication/__init__.py renamed to app/eSignature/examples/eg020_phone_authentication/__init__.py

File renamed without changes.

app/eSignature/examples/eg020_sms_authentication/controller.py renamed to app/eSignature/examples/eg020_phone_authentication/controller.py

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
11
import base64
22
from os import path
33

4-
from docusign_esign import EnvelopesApi, EnvelopeDefinition, Document, Signer, SignHere, Tabs, Recipients
5-
from flask import request, session
4+
from docusign_esign import AccountsApi, EnvelopesApi, EnvelopeDefinition, Document, Signer, SignHere, Tabs, Recipients, RecipientIdentityInputOption, RecipientIdentityPhoneNumber
5+
from docusign_esign.client.api_exception import ApiException
6+
from flask import current_app as app, session, request
67

78
from ....consts import demo_docs_path, pattern
89
from ....docusign import create_api_client
910
from ....ds_config import DS_CONFIG
11+
from ....error_handlers import process_error
1012

1113

1214
class Eg020Controller:
1315
@staticmethod
1416
def get_args():
1517
"""Get required session and request arguments"""
1618
# More data validation would be a good idea here
17-
# Strip anything other than characters listed
18-
phone_number = request.form.get("phone_number")
19+
# Strip anything other than the characters listed
1920
signer_email = pattern.sub("", request.form.get("signer_email"))
2021
signer_name = pattern.sub("", request.form.get("signer_name"))
22+
country_code = pattern.sub("", request.form.get("country_code"))
23+
phone_number = pattern.sub("", request.form.get("phone_number"))
2124
envelope_args = {
2225
"signer_email": signer_email,
2326
"signer_name": signer_name,
27+
"phone_number": phone_number,
28+
"country_code": country_code,
2429
"status": "sent",
25-
"phone_number": phone_number
30+
"workflow_id": session['workflow_id']
2631
}
27-
2832
args = {
2933
"account_id": session["ds_account_id"], # represents your {ACCOUNT_ID}
3034
"base_path": session["ds_base_path"],
@@ -38,12 +42,11 @@ def worker(args):
3842
"""
3943
1. Create an api client
4044
2. Create an envelope definition object
41-
3. Call the eSignature REST API using the SDK
4245
"""
4346
# Step 1: Construct your API headers
4447
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
4548

46-
# Step 2: Construct your envelope
49+
# Step 3: Construct your envelope
4750
envelope_definition = EnvelopeDefinition(
4851
email_subject="Please sign this document set"
4952
)
@@ -53,7 +56,7 @@ def worker(args):
5356
content_bytes = file.read()
5457
base64_file_content = base64.b64encode(content_bytes).decode("ascii")
5558

56-
# Add a Document
59+
# Add a document
5760
document1 = Document( # create the DocuSign document object
5861
document_base64=base64_file_content,
5962
document_id="1", # a label used to reference the doc
@@ -64,16 +67,6 @@ def worker(args):
6467
envelope_definition.documents = [document1]
6568
envelope_definition.status = args["envelope_args"]["status"]
6669

67-
signer1 = Signer(
68-
email=args["envelope_args"]["signer_email"], # represents your {signer_email}
69-
name=args["envelope_args"]["signer_name"], # represents your {signer_name}
70-
sms_authentication={"senderProvidedNumbers": [args["envelope_args"]["phone_number"]]},
71-
id_check_configuration_name="SMS Auth $",
72-
require_id_lookup="true",
73-
recipient_id="1",
74-
routing_order="1"
75-
)
76-
7770
# Create your signature tab
7871
sign_here1 = SignHere(
7972
name="SignHereTab",
@@ -87,14 +80,50 @@ def worker(args):
8780
recipient_id="1" # represents your {RECIPIENT_ID}
8881
)
8982

90-
# Add the tabs model (including the sign_here tabs) to the signer
91-
# The Tabs object wants arrays of the different field/tab types
92-
signer1.tabs = Tabs(sign_here_tabs=[sign_here1])
83+
signer1 = Signer(
84+
email=args["envelope_args"]["signer_email"], # Represents your {signer_email}
85+
name=args["envelope_args"]["signer_name"], # Represents your {signer_name}
86+
role_name="",
87+
note="",
88+
status="created",
89+
delivery_method="email",
90+
recipient_id="1", # Represents your {RECIPIENT_ID}
91+
routing_order="1",
92+
identity_verification={ "workflowId": "c368e411-1592-4001-a3df-dca94ac539ae", "steps": "null", "inputOptions":[{"name":"phone_number_list","valueType":"PhoneNumberList","phoneNumberList":[{"countryCode":args["envelope_args"]["country_code"],"code":"1","number":args["envelope_args"]["phone_number"]}]}], "idCheckConfigurationName":""},
93+
tabs=Tabs(sign_here_tabs=[sign_here1])
94+
)
9395

9496
# Tabs are set per recipient
9597
envelope_definition.recipients = Recipients(signers=[signer1])
96-
# Step 3: Call the eSignature REST API
97-
envelope_api = EnvelopesApi(api_client)
98-
results = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
98+
99+
# Step 4: Call the eSignature REST API
100+
envelopes_api = EnvelopesApi(api_client)
101+
results = envelopes_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
99102

100103
return results
104+
105+
@staticmethod
106+
def get_workflow(args):
107+
"""Retrieve the workflow id"""
108+
"""try:
109+
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
110+
111+
workflow_details = AccountsApi(api_client)
112+
workflow_response = workflow_details.get_account_identity_verification(account_id=args["account_id"])
113+
114+
# Check that idv authentication is enabled
115+
if workflow_response.identity_verification:
116+
workflow_id = workflow_response.identity_verification[0].workflow_id
117+
app.logger.info("We found the following workflowID: " + workflow_id)
118+
session['workflow_id'] = workflow_id
119+
120+
return workflow_id
121+
122+
else:
123+
return None
124+
125+
except ApiException as err:
126+
return process_error(err)"""
127+
128+
session['workflow_id'] = "c368e411-1592-4001-a3df-dca94ac539ae"
129+
return "c368e411-1592-4001-a3df-dca94ac539ae"

app/eSignature/examples/eg020_sms_authentication/views.py renamed to app/eSignature/examples/eg020_phone_authentication/views.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
""" Example 020: Sms Recipient Authentication"""
1+
""" Example 020: Recipient Phone Authentication"""
22

33
from os import path
44

55
from docusign_esign.client.api_exception import ApiException
66
from flask import current_app as app
7-
from flask import render_template, Blueprint
7+
from flask import render_template, Blueprint, session
88

99
from .controller import Eg020Controller
1010
from ....docusign import authenticate
@@ -17,7 +17,7 @@
1717

1818
@eg020.route("/eg020", methods=["POST"])
1919
@authenticate(eg=eg)
20-
def sms_authentication():
20+
def phone_authentication():
2121
"""
2222
1. Get required arguments
2323
2. Call the worker method
@@ -27,7 +27,7 @@ def sms_authentication():
2727
# 1. Get required arguments
2828
args = Eg020Controller.get_args()
2929
try:
30-
# Step 2: Call the worker method for sms authenticating
30+
# Step 2: Call the worker method for authenticating with phone
3131
results = Eg020Controller.worker(args)
3232
envelope_id = results.envelope_id
3333
app.logger.info(f"Envelope was created. EnvelopeId {envelope_id} ")
@@ -49,13 +49,22 @@ def sms_authentication():
4949
def get_view():
5050
"""Responds with the form for the example"""
5151

52+
args = {
53+
"account_id": session["ds_account_id"], # represent your {ACCOUNT_ID}
54+
"base_path": session["ds_base_path"],
55+
"access_token": session["ds_access_token"], # represent your {ACCESS_TOKEN}
56+
}
57+
58+
workflow_id = Eg020Controller.get_workflow(args)
59+
5260
return render_template(
53-
"eg020_sms_authentication.html",
54-
title="SMS recipient authentication",
61+
"eg020_phone_authentication.html",
62+
title="Phone recipient authentication",
5563
source_file=path.basename(path.dirname(__file__)) + "/controller.py",
5664
source_url=DS_CONFIG["github_example_url"] + path.basename(path.dirname(__file__)) + "/controller.py",
5765
documentation=DS_CONFIG["documentation"] + eg,
5866
show_doc=DS_CONFIG["documentation"],
5967
signer_name=DS_CONFIG["signer_name"],
60-
signer_email=DS_CONFIG["signer_email"]
68+
signer_email=DS_CONFIG["signer_email"],
69+
workflow_id = workflow_id
6170
)
Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
import base64
22
from os import path
33

4-
from docusign_esign import EnvelopesApi, EnvelopeDefinition, Document, Signer, SignHere, Tabs, Recipients
5-
from flask import session, request
4+
from docusign_esign import AccountsApi, EnvelopesApi, EnvelopeDefinition, Document, Signer, SignHere, Tabs, Recipients, RecipientIdentityInputOption, RecipientIdentityPhoneNumber
5+
from docusign_esign.client.api_exception import ApiException
6+
from flask import current_app as app, session, request
67

78
from ....consts import demo_docs_path, pattern
89
from ....docusign import create_api_client
910
from ....ds_config import DS_CONFIG
11+
from ....error_handlers import process_error
1012

1113

1214
class Eg021Controller:
1315
@staticmethod
1416
def get_args():
1517
"""Get required session and request arguments"""
1618
# More data validation would be a good idea here
17-
# Strip anything other than characters listed
18-
phone_number = request.form.get("phoneNumber")
19+
# Strip anything other than the characters listed
1920
signer_email = pattern.sub("", request.form.get("signer_email"))
2021
signer_name = pattern.sub("", request.form.get("signer_name"))
22+
country_code = pattern.sub("", request.form.get("country_code"))
23+
phone_number = pattern.sub("", request.form.get("phone_number"))
2124
envelope_args = {
2225
"signer_email": signer_email,
2326
"signer_name": signer_name,
27+
"phone_number": phone_number,
28+
"country_code": country_code,
2429
"status": "sent",
25-
"phone_number": phone_number
30+
"workflow_id": session['workflow_id']
2631
}
2732
args = {
2833
"account_id": session["ds_account_id"], # represents your {ACCOUNT_ID}
@@ -37,12 +42,11 @@ def worker(args):
3742
"""
3843
1. Create an api client
3944
2. Create an envelope definition object
40-
3. Call the eSignature REST API using the SDK
4145
"""
4246
# Step 1: Construct your API headers
4347
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
4448

45-
# Step 2: Construct your envelope
49+
# Step 3: Construct your envelope
4650
envelope_definition = EnvelopeDefinition(
4751
email_subject="Please sign this document set"
4852
)
@@ -52,7 +56,7 @@ def worker(args):
5256
content_bytes = file.read()
5357
base64_file_content = base64.b64encode(content_bytes).decode("ascii")
5458

55-
# Add a Document
59+
# Add a document
5660
document1 = Document( # create the DocuSign document object
5761
document_base64=base64_file_content,
5862
document_id="1", # a label used to reference the doc
@@ -63,16 +67,6 @@ def worker(args):
6367
envelope_definition.documents = [document1]
6468
envelope_definition.status = args["envelope_args"]["status"]
6569

66-
signer1 = Signer(
67-
email=args["envelope_args"]["signer_email"], # represents your {signer_email}
68-
name=args["envelope_args"]["signer_name"], # represents your {signer_name}
69-
phone_authentication={"senderProvidedNumbers": [args["envelope_args"]["phone_number"]]},
70-
id_check_configuration_name="Phone Auth $",
71-
require_id_lookup="true",
72-
recipient_id="1",
73-
routing_order="1"
74-
)
75-
7670
# Create your signature tab
7771
sign_here1 = SignHere(
7872
name="SignHereTab",
@@ -86,14 +80,50 @@ def worker(args):
8680
recipient_id="1" # represents your {RECIPIENT_ID}
8781
)
8882

89-
# Add the tabs model (including the sign_here tabs) to the signer
90-
# The Tabs object wants arrays of the different field/tab types
91-
signer1.tabs = Tabs(sign_here_tabs=[sign_here1])
83+
signer1 = Signer(
84+
email=args["envelope_args"]["signer_email"], # Represents your {signer_email}
85+
name=args["envelope_args"]["signer_name"], # Represents your {signer_name}
86+
role_name="",
87+
note="",
88+
status="created",
89+
delivery_method="email",
90+
recipient_id="1", # Represents your {RECIPIENT_ID}
91+
routing_order="1",
92+
identity_verification={ "workflowId": "c368e411-1592-4001-a3df-dca94ac539ae", "steps": "null", "inputOptions":[{"name":"phone_number_list","valueType":"PhoneNumberList","phoneNumberList":[{"countryCode":args["envelope_args"]["country_code"],"code":"1","number":args["envelope_args"]["phone_number"]}]}], "idCheckConfigurationName":""},
93+
tabs=Tabs(sign_here_tabs=[sign_here1])
94+
)
9295

9396
# Tabs are set per recipient
9497
envelope_definition.recipients = Recipients(signers=[signer1])
95-
# Step 3: Call the eSignature REST API
96-
envelope_api = EnvelopesApi(api_client)
97-
results = envelope_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
98+
99+
# Step 4: Call the eSignature REST API
100+
envelopes_api = EnvelopesApi(api_client)
101+
results = envelopes_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition)
98102

99103
return results
104+
105+
@staticmethod
106+
def get_workflow(args):
107+
"""Retrieve the workflow id"""
108+
"""try:
109+
api_client = create_api_client(base_path=args["base_path"], access_token=args["access_token"])
110+
111+
workflow_details = AccountsApi(api_client)
112+
workflow_response = workflow_details.get_account_identity_verification(account_id=args["account_id"])
113+
114+
# Check that idv authentication is enabled
115+
if workflow_response.identity_verification:
116+
workflow_id = workflow_response.identity_verification[0].workflow_id
117+
app.logger.info("We found the following workflowID: " + workflow_id)
118+
session['workflow_id'] = workflow_id
119+
120+
return workflow_id
121+
122+
else:
123+
return None
124+
125+
except ApiException as err:
126+
return process_error(err)"""
127+
128+
session['workflow_id'] = "c368e411-1592-4001-a3df-dca94ac539ae"
129+
return "c368e411-1592-4001-a3df-dca94ac539ae"

app/eSignature/examples/eg021_phone_authentication/views.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from docusign_esign.client.api_exception import ApiException
66
from flask import current_app as app
7-
from flask import render_template, Blueprint
7+
from flask import render_template, Blueprint, session
88

99
from .controller import Eg021Controller
1010
from ....docusign import authenticate
@@ -49,6 +49,14 @@ def phone_authentication():
4949
def get_view():
5050
"""Responds with the form for the example"""
5151

52+
args = {
53+
"account_id": session["ds_account_id"], # represent your {ACCOUNT_ID}
54+
"base_path": session["ds_base_path"],
55+
"access_token": session["ds_access_token"], # represent your {ACCESS_TOKEN}
56+
}
57+
58+
workflow_id = Eg021Controller.get_workflow(args)
59+
5260
return render_template(
5361
"eg021_phone_authentication.html",
5462
title="Phone recipient authentication",
@@ -57,5 +65,6 @@ def get_view():
5765
documentation=DS_CONFIG["documentation"] + eg,
5866
show_doc=DS_CONFIG["documentation"],
5967
signer_name=DS_CONFIG["signer_name"],
60-
signer_email=DS_CONFIG["signer_email"]
68+
signer_email=DS_CONFIG["signer_email"],
69+
workflow_id = workflow_id
6170
)

0 commit comments

Comments
 (0)