| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
9 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,7 +55,6 @@ def worker(cls, args): | |||
| 55 | 55 | results = envelopes_api.create_envelope(account_id=args["account_id"], envelope_definition=envelope_definition) | |
| 56 | 56 | ||
| 57 | 57 | envelope_id = results.envelope_id | |
| 58 | - app.logger.info(f"Envelope was created. EnvelopeId {envelope_id}") | ||
| 59 | 58 | ||
| 60 | 59 | # 3. Create the RecipientViewRequest object | |
| 61 | 60 | recipient_view_request = RecipientViewRequest( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,7 @@ | |||
| 3 | 3 | from os import path | |
| 4 | 4 | ||
| 5 | 5 | from docusign_esign.client.api_exception import ApiException | |
| 6 | - from flask import render_template, redirect, session, Blueprint | ||
| 6 | + from flask import render_template, redirect, session, Blueprint, current_app | ||
| 7 | 7 | ||
| 8 | 8 | from ..examples.eg016_set_tab_values import Eg016SetTabValuesController | |
| 9 | 9 | from ...docusign import authenticate, ensure_manifest, get_example_by_number | |
@@ -35,6 +35,7 @@ def set_tab_values(): | |||
| 35 | 35 | try: | |
| 36 | 36 | # 2. Call the worker method for setting tab values | |
| 37 | 37 | results = Eg016SetTabValuesController.worker(args) | |
| 38 | + current_app.logger.info(f"Envelope was created. EnvelopeId {results['envelope_id']}") | ||
| 38 | 39 | except ApiException as err: | |
| 39 | 40 | return process_error(err) | |
| 40 | 41 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,80 @@ | |||
| 1 | + import os | ||
| 2 | + import base64 | ||
| 3 | + from docusign_esign import ApiClient | ||
| 4 | + from docusign_esign.client.api_exception import ApiException | ||
| 5 | + | ||
| 6 | + from ..ds_config import DS_CONFIG, DS_JWT | ||
| 7 | + | ||
| 8 | + DATA = { | ||
| 9 | + "signer_client_id": '1000', | ||
| 10 | + "return_url": DS_CONFIG["app_url"] + "/ds-return", | ||
| 11 | + "ping_url": DS_CONFIG["app_url"] + "/", | ||
| 12 | + "private_key_filename": "../config/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 | + | ||
| 30 | + class TestHelper: | ||
| 31 | + @staticmethod | ||
| 32 | + def authenticate(): | ||
| 33 | + try: | ||
| 34 | + private_key_file = open(os.path.abspath(os.path.join(DS_JWT["private_key_file"])), "r") | ||
| 35 | + private_key = private_key_file.read() | ||
| 36 | + | ||
| 37 | + api_client = ApiClient() | ||
| 38 | + api_client.host = DATA["base_path"] | ||
| 39 | + | ||
| 40 | + api_client = ApiClient() | ||
| 41 | + api_client.set_base_path(DATA["base_path"]) | ||
| 42 | + api_client.set_oauth_host_name(DATA["oauth_base_path"]) | ||
| 43 | + token_response = api_client.request_jwt_user_token( | ||
| 44 | + client_id=DS_JWT["ds_client_id"], | ||
| 45 | + user_id=DS_JWT["ds_impersonated_user_id"], | ||
| 46 | + oauth_host_name=DATA["oauth_base_path"], | ||
| 47 | + private_key_bytes=private_key, | ||
| 48 | + expires_in=4000, | ||
| 49 | + scopes=DATA["scopes"] | ||
| 50 | + ) | ||
| 51 | + | ||
| 52 | + access_token = token_response.access_token | ||
| 53 | + | ||
| 54 | + # Save API account ID | ||
| 55 | + user_info = api_client.get_user_info(access_token) | ||
| 56 | + accounts = user_info.get_accounts() | ||
| 57 | + api_account_id = accounts[0].account_id | ||
| 58 | + base_path = accounts[0].base_uri + "/restapi" | ||
| 59 | + | ||
| 60 | + return {"access_token": access_token, "account_id": api_account_id, "base_path": base_path} | ||
| 61 | + except ApiException as err: | ||
| 62 | + body = err.body.decode('utf8') | ||
| 63 | + | ||
| 64 | + if "consent_required" in body: | ||
| 65 | + url_scopes = "+".join(DATA["scopes"]) | ||
| 66 | + url = f"https://{DS_JWT['authorization_server']}/oauth/auth?response_type=code&" \ | ||
| 67 | + f"scope={url_scopes}&client_id={DS_JWT['ds_client_id']}&redirect_uri={DATA['redirect_uri']}" | ||
| 68 | + | ||
| 69 | + consent_message = f"You should grant access by making the following call: {url}" | ||
| 70 | + print(consent_message) | ||
| 71 | + raise Exception(f"You should grant access by making the following call: {url}") | ||
| 72 | + | ||
| 73 | + @staticmethod | ||
| 74 | + def read_as_base64(path): | ||
| 75 | + with open(path, "rb") as file: | ||
| 76 | + content_bytes = file.read() | ||
| 77 | + base64_file_content = base64.b64encode(content_bytes).decode("ascii") | ||
| 78 | + | ||
| 79 | + return base64_file_content | ||
| 80 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments