Skip to content

Commit 65d7f86

Browse files
fix incompatibility (#111)
1 parent da3a0d2 commit 65d7f86

8 files changed

Lines changed: 145 additions & 141 deletions

File tree

.github/workflows/python.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@ jobs:
2323
uses: actions/setup-python@v3
2424
with:
2525
python-version: "3.10"
26-
26+
2727
- name: Install dependencies
2828
run: |
2929
python -m pip install --upgrade pip
3030
pip install flake8 pytest
3131
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32-
32+
3333
- name: Lint with flake8
3434
run: flake8
35-
35+
3636
- name: Write private key
3737
run: |
3838
echo '${{ secrets.PRIVATE_KEY }}' >> app/private.key
39+
cp app/ds_config_sample.py app/ds_config.py
3940
4041
- name: Test with pytest
4142
run: pytest

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
app/.env
1+
app/ds_config.py
22

33
*/.DS_Store
44
.DS_Store

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,31 @@ For a list of code examples that use the Admin API, see the [How-to guides overv
8888
1. In your command-line environment, switch to the folder:
8989
`cd <Quickstart folder>` or `cd code-examples-python`
9090
1. To install dependencies, run: `pip3 install -r requirements.txt` (or pipenv can be used)
91-
1. To configure the launcher for [Authorization Code Grant](https://developers.docusign.com/platform/auth/authcode/) authentication, create a copy of the file `app/.env.example` and save the copy as `app/.env`.
92-
1. Add your integration key. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **Apps and Integration Keys**, choose the app to use, then select **Actions > Edit**. Under **General Info**, copy the **Integration Key** GUID and save it in .env as your `CLIENT_ID`.
93-
1. Generate a secret key, if you don’t already have one. Under **Authentication**, select **+ ADD SECRET KEY**. Copy the secret key and save it in .env as your `CLIENT_SECRET`.
91+
1. To configure the launcher for [Authorization Code Grant](https://developers.docusign.com/platform/auth/authcode/) authentication, create a copy of the file app/ds_config_sample.py and save the copy as app/ds_config.py.
92+
1. Add your integration key. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **Apps and Integration Keys**, choose the app to use, then select **Actions > Edit**. Under **General Info**, copy the **Integration Key** GUID and save it in ds_config.py as your `ds_client_id`.
93+
1. Generate a secret key, if you don’t already have one. Under **Authentication**, select **+ ADD SECRET KEY**. Copy the secret key and save it in ds_config.py as your `ds_client_secret`.
9494
1. Add the launcher’s redirect URI. Under **Additional settings**, select **+ ADD URI**, and set a redirect URI of http://localhost:3000/ds/callback. Select **SAVE**.
95-
1. Set a name and email address for the signer. In .env, save an email address as `SIGNER_EMAIL` and a name as `SIGNER_NAME`.
96-
**Note:** Protect your personal information. Please make sure that .env will not be stored in your source code repository.
95+
1. Set a name and email address for the signer. In ds_config.py, save an email address as `signer_email` and a name as `signer_name`.
96+
**Note:** Protect your personal information. Please make sure that ds_config.py will not be stored in your source code repository.
9797
1. Run the launcher:`python run.py`
9898
**Note:** You will need to alias the python command to run Python 3 or use `python3 run.py`
9999
1. Open a browser to http://localhost:3000
100100

101101
### Installation steps for JWT Grant authentication
102102

103103
**Note:** If you downloaded this code using [Quickstart](https://developers.docusign.com/docs/esign-rest-api/quickstart/) from the DocuSign Developer Center, skip step 4 as it was automatically performed for you.
104-
Also, in order to select JSON Web Token authentication in the launcher, in app/.env, change the `QUICKSTART_VALUE` setting to `"false"`.
104+
Also, in order to select JSON Web Token authentication in the launcher, in app/ds_config.py, change the `quickstart` setting to `"false"`.
105105

106106
1. Extract the Quickstart ZIP file or download or clone the code-examples-python repository.
107107
1. In your command-line environment, switch to the folder: `cd <Quickstart folder>` or `cd code-examples-python`
108108
1. To install dependencies, run: `pip3 install -r requirements.txt` (or pipenv can be used)
109-
1. To configure the launcher for [JWT Grant](https://developers.docusign.com/platform/auth/jwt/) authentication, create a copy of the file `app/.env.example` and save the copy as `app/.env`.
110-
1. Add your User ID. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **My Account Information**, copy the **User ID** GUID and save it in .env as your `USER_ID`.
111-
1. Add your integration key. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **Apps and Integration Keys**, choose the app to use, then select **Actions > Edit**. Under **General Info**, copy the **Integration Key** GUID and save it in .env as your `CLIENT_ID`.
109+
1. To configure the launcher for [JWT Grant](https://developers.docusign.com/platform/auth/jwt/) authentication, create a copy of the file app/ds_config_sample.py and save the copy as app/ds_config.py.
110+
1. Add your User ID. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **My Account Information**, copy the **User ID** GUID and save it in ds_config.py as your `ds_impersonated_user_id`.
111+
1. Add your integration key. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **Apps and Integration Keys**, choose the app to use, then select **Actions > Edit**. Under **General Info**, copy the **Integration Key** GUID and save it in ds_config.py as your `ds_client_id`.
112112
1. Generate an RSA key pair, if you don’t already have one. Under **Authentication**, select **+ GENERATE RSA**. Copy the private key, and save it in a new file named app/private.key.
113113
1. Add the launcher’s redirect URI. Under **Additional settings**, select **+ ADD URI**, and set a redirect URI of http://localhost:3000/ds/callback. Select **SAVE**.
114-
1. Set a name and email address for the signer. In .env, save an email address as `SIGNER_EMAIL` and a name as `SIGNER_NAME`.
115-
**Note:** Protect your personal information. Please make sure that your .env and private.key files will not be stored in your source code repository.
114+
1. Set a name and email address for the signer. In ds_config.py, save an email address as `signer_email` and a name as `signer_name`.
115+
**Note:** Protect your personal information. Please make sure that your ds_config.py and private.key files will not be stored in your source code repository.
116116
1. Run the launcher:`python run.py`
117117
**Note:** You will need to alias the python command to run Python 3 or use `python3 run.py`
118118
1. Open a browser to http://localhost:3000
@@ -143,7 +143,7 @@ Follow the instructions below if you downloaded the JWT grant remote signing exa
143143

144144
To use the payments code example, create a test payment gateway on the [Payments](https://admindemo.docusign.com/authenticate?goTo=payments) page in your developer account. See [Configure a payment gateway](./PAYMENTS_INSTALLATION.md) for details.
145145

146-
Once you've created a payment gateway, save the **Gateway Account ID** GUID and **Getaway Account Name and Display Name** to .env.
146+
Once you've created a payment gateway, save the **Gateway Account ID** GUID to ds_config.py.
147147

148148

149149
## License and additional information
@@ -153,4 +153,4 @@ This repository uses the MIT License. See [LICENSE](./LICENSE) for details.
153153

154154
### Pull Requests
155155
Pull requests are welcomed. Pull requests will only be considered if their content
156-
uses the MIT License.
156+
uses the MIT License.

app/.env.example

Lines changed: 0 additions & 20 deletions
This file was deleted.

app/ds_config_sample.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
"ds_impersonated_user_id": "{IMPERSONATED_USER_ID}", # The id of the user.
4545
"private_key_file": "./app/private.key", # Create a new file in your repo source folder named private.key then copy and paste your RSA private key there and save it.
4646
"authorization_server": "account-d.docusign.com"
47-
}
47+
}

app/tests/test_config.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import os
2+
from dotenv import load_dotenv
3+
4+
load_dotenv()
5+
6+
7+
def get_configuration():
8+
data = {
9+
"signer_client_id": '1000',
10+
"return_url": "http://localhost:5000/ds-return",
11+
"ping_url": "http://localhost:5000/",
12+
"private_key_filename": "./app/private.key",
13+
"base_path": 'https://demo.docusign.net/restapi',
14+
"oauth_base_path": 'account-d.docusign.com',
15+
"redirect_uri": 'https://www.docusign.com/api',
16+
"scopes": ["signature", "impersonation"],
17+
"expires_in": 3600,
18+
"test_pdf_file": './app/tests/docs/World_Wide_Corp_lorem.pdf',
19+
"test_docx_file": './app/tests/docs/World_Wide_Corp_Battle_Plan_Trafalgar.docx',
20+
"test_template_pdf_file": './app/tests/docs/World_Wide_Corp_fields.pdf',
21+
"test_template_docx_file": './app/tests/docs/World_Wide_Corp_salary.docx',
22+
"template_name": 'Example Signer and CC template',
23+
"cc_name": 'Test Name',
24+
"cc_email": 'test@mail.com',
25+
"item": 'Item',
26+
"quantity": '5'
27+
}
28+
29+
if os.environ.get("CLIENT_ID") is not None:
30+
config = {
31+
"ds_client_id": os.environ.get("CLIENT_ID"),
32+
"ds_impersonated_user_id": os.environ.get("USER_ID"),
33+
"signer_email": os.environ.get("SIGNER_EMAIL"),
34+
"signer_name": os.environ.get("SIGNER_NAME"),
35+
"private_key_file": "./app/private.key"
36+
}
37+
else:
38+
from ..ds_config import DS_CONFIG, DS_JWT
39+
40+
config = {
41+
"ds_client_id": DS_JWT["ds_client_id"],
42+
"ds_impersonated_user_id": DS_JWT["ds_impersonated_user_id"],
43+
"signer_email": DS_CONFIG["signer_email"],
44+
"signer_name": DS_CONFIG["signer_name"],
45+
"private_key_file": DS_JWT["private_key_file"]
46+
}
47+
48+
return data | config

app/tests/test_helper.py

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,9 @@
22
import base64
33
from docusign_esign import ApiClient
44
from docusign_esign.client.api_exception import ApiException
5+
from .test_config import get_configuration
56

6-
from ..ds_config import DS_CONFIG, DS_JWT
7-
8-
9-
CONFIG = {
10-
"ds_client_id": DS_JWT["ds_client_id"],
11-
"ds_impersonated_user_id": DS_JWT["ds_impersonated_user_id"],
12-
"signer_email": DS_CONFIG["signer_email"],
13-
"signer_name": DS_CONFIG["signer_name"],
14-
"private_key_file": DS_JWT["private_key_file"]
15-
}
16-
17-
DATA = {
18-
"signer_client_id": '1000',
19-
"return_url": "http://localhost:5000/ds-return",
20-
"ping_url": "http://localhost:5000/",
21-
"private_key_filename": "../config/private.key",
22-
"base_path": 'https://demo.docusign.net/restapi',
23-
"oauth_base_path": 'account-d.docusign.com',
24-
"redirect_uri": 'https://www.docusign.com/api',
25-
"scopes": ["signature", "impersonation"],
26-
"expires_in": 3600,
27-
"test_pdf_file": './app/tests/docs/World_Wide_Corp_lorem.pdf',
28-
"test_docx_file": './app/tests/docs/World_Wide_Corp_Battle_Plan_Trafalgar.docx',
29-
"test_template_pdf_file": './app/tests/docs/World_Wide_Corp_fields.pdf',
30-
"test_template_docx_file": './app/tests/docs/World_Wide_Corp_salary.docx',
31-
"template_name": 'Example Signer and CC template',
32-
"cc_name": 'Test Name',
33-
"cc_email": 'test@mail.com',
34-
"item": 'Item',
35-
"quantity": '5'
36-
}
7+
CONFIG = get_configuration()
378

389

3910
class TestHelper:
@@ -44,18 +15,18 @@ def authenticate():
4415
private_key = private_key_file.read()
4516

4617
api_client = ApiClient()
47-
api_client.host = DATA["base_path"]
18+
api_client.host = CONFIG["base_path"]
4819

4920
api_client = ApiClient()
50-
api_client.set_base_path(DATA["base_path"])
51-
api_client.set_oauth_host_name(DATA["oauth_base_path"])
21+
api_client.set_base_path(CONFIG["base_path"])
22+
api_client.set_oauth_host_name(CONFIG["oauth_base_path"])
5223
token_response = api_client.request_jwt_user_token(
5324
client_id=CONFIG["ds_client_id"],
5425
user_id=CONFIG["ds_impersonated_user_id"],
55-
oauth_host_name=DATA["oauth_base_path"],
26+
oauth_host_name=CONFIG["oauth_base_path"],
5627
private_key_bytes=private_key,
57-
expires_in=DATA["expires_in"],
58-
scopes=DATA["scopes"]
28+
expires_in=CONFIG["expires_in"],
29+
scopes=CONFIG["scopes"]
5930
)
6031

6132
access_token = token_response.access_token
@@ -71,14 +42,16 @@ def authenticate():
7142
body = err.body.decode('utf8')
7243

7344
if "consent_required" in body:
74-
url_scopes = "+".join(DATA["scopes"])
75-
url = f"https://{DATA['oauth_base_path']}/oauth/auth?response_type=code&" \
76-
f"scope={url_scopes}&client_id={CONFIG['ds_client_id']}&redirect_uri={DATA['redirect_uri']}"
45+
url_scopes = "+".join(CONFIG["scopes"])
46+
url = f"https://{CONFIG['oauth_base_path']}/oauth/auth?response_type=code&" \
47+
f"scope={url_scopes}&client_id={CONFIG['ds_client_id']}&redirect_uri={CONFIG['redirect_uri']}"
7748

7849
consent_message = f"You should grant access by making the following call: {url}"
7950
print(consent_message)
8051
raise Exception(f"You should grant access by making the following call: {url}")
8152

53+
raise err
54+
8255
@staticmethod
8356
def read_as_base64(path):
8457
with open(path, "rb") as file:

0 commit comments

Comments
 (0)