def __init__(self): load("credentials.json") as f: self._user_name = f["Docusign"]["Username"] self._integrator_key = f["Docusign"]["Integrator_Key"] self._base_url = "https://demo.docusign.net/restapi" self._oauth_base_url = "account.docusign.com" self._redirect_uri = "https://www.docusign.com/api" self._private_key_filename = "keys/docusign_private_key.txt" self._user_id = f["Docusign"]["User_ID"] self._template_id = f["Docusign"]["Template_ID"] self._api_client = docusign.ApiClient(base_url) self._oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url)
def create_api_client( host: str, access_token: Union[None, str, dse.OAuthToken] = None) -> dse.ApiClient: api_client = dse.ApiClient() api_client.host = host if isinstance(access_token, dse.OAuthToken): access_token = access_token.access_token if access_token: api_client.set_default_header("Authorization", f"Bearer {access_token}") return api_client
def setUp(self): self.api_client = docusign.ApiClient(base_path=BaseUrl, oauth_host_name=OauthHostName) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client try: email_subject = 'Please Sign my Python SDK Envelope' email_blurb = 'Hello, Please sign my Python SDK Envelope.' template_id = TemplateId role_name = 'Needs to sign' name = 'Pat Developer' email = Username t_role = docusign.TemplateRole(role_name=role_name, name=name, email=email) # send the envelope by setting |status| to "sent". To save as a draft set to "created" status = 'sent' # create an envelope definition envelope_definition = docusign.EnvelopeDefinition( email_subject=email_subject, email_blurb=email_blurb, template_id=template_id, template_roles=[t_role], status=status) envelopes_api = EnvelopesApi() self.api_client.host = BaseUrl token = (self.api_client.request_jwt_user_token( client_id=IntegratorKey, user_id=UserId, oauth_host_name=OauthHostName, private_key_bytes=PrivateKeyBytes, expires_in=3600)) self.user_info = self.api_client.get_user_info(token.access_token) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) self.api_client.rest_client.pool_manager.clear() self.envelope_id = envelope_summary.envelope_id except ApiException as e: print("\nException when calling DocuSign API: %s" % e) except Exception as e: print("\nException when calling DocuSign API: %s" % e) self.api_client.rest_client.pool_manager.clear()
def main(): api_client = docusign.ApiClient() CONSENT_REDIRECT_URL = "https://www.docusign.com" # Just used for individual permission request try: print("\nSending an envelope...") result = SendEnvelope(api_client).send_envelope() print( f"Envelope status: {result.status}. Envelope ID: {result.envelope_id}" ) print( "\nList envelopes in the account whose status changed in the last 30 days..." ) envelopes_list = ListEnvelopes(api_client).list() envelopes = envelopes_list.envelopes num_envelopes = len(envelopes) if num_envelopes > 2: print( f"Results for {num_envelopes} envelopes were returned. Showing the first two:\n" ) envelopes_list.envelopes = [envelopes[0], envelopes[1]] else: print(f"Results for {num_envelopes} envelopes were returned:\n") DSHelper.print_pretty_json(envelopes_list) except docusign.ApiException as err: print("\n\nDocuSign Exception!") # Special handling for consent_required body = err.body.decode('utf8') if "consent_required" in body: consent_scopes = "signature%20impersonation" consent_url = f"{DSConfig.auth_server()}/oauth/auth?response_type=code&scope={consent_scopes}&client_id={DSConfig.client_id()}&redirect_uri={CONSENT_REDIRECT_URL}" print(f""" \nC O N S E N T R E Q U I R E D Ask the user who will be impersonated to run the following url: {consent_url} It will ask the user to login and to approve access by your application. Alternatively, an Administrator can use Organization Administration to pre-approve one or more users.""") else: print(f" Reason: {err.reason}") print(f" Error response: {err.body.decode('utf8')}") print("\nDone.\n")
def testOAuthLogin(self): # create a separate api client for this test case api_client = docusign.ApiClient(BASE_URL) # make sure to pass the redirect uri api_client.configure_authorization_flow(integrator_key, client_secret, redirect_uri) # get DocuSign OAuth authorization url oauth_login_url = api_client.get_authorization_uri() # open DocuSign OAuth login in the browser print(oauth_login_url) # webbrowser.open_new_tab(oauth_login_url) # IMPORTANT NOTE: after the login, DocuSign will send back a fresh authorization code as a query param of the redirect URI. # You should set up a route that handles the redirect call to get that code and pass it to token endpoint as shown in the next lines: '''
def setUp(self): self.api_client = docusign.ApiClient(BASE_URL) # IMPORTANT NOTE: # the first time you ask for a JWT access token, you should grant access by making the following call # get DocuSign OAuth authorization url: oauth_login_url = self.api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url) # open DocuSign OAuth authorization url in the browser, login and grant access # webbrowser.open_new_tab(oauth_login_url) print(oauth_login_url) # END OF NOTE # configure the ApiClient to asynchronously get an access to token and store it self.api_client.configure_jwt_authorization_flow(private_key_filename, oauth_base_url, integrator_key, user_id, 3600) docusign.configuration.api_client = self.api_client
def setUp(self): self.api_client = docusign.ApiClient(base_path=BaseUrl, oauth_host_name=OauthHostName) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client self.private_key_file_name = "{}/keys/private.pem".format( os.path.dirname(os.path.abspath(__file__))) try: envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' envelope_definition.template_id = TemplateId t_role = docusign.TemplateRole() t_role.role_name = 'Needs to sign' t_role.name = 'Pat Developer' t_role.email = Username envelope_definition.template_roles = [t_role] # send the envelope by setting |status| to "sent". To save as a draft set to "created" envelope_definition.status = 'sent' envelopes_api = EnvelopesApi() with open(self.private_key_file_name, 'r') as private_key: self.api_client.host = BaseUrl token = (self.api_client.request_jwt_user_token( client_id=IntegratorKey, user_id=UserId, oauth_host_name=OauthHostName, private_key_bytes=private_key.read(), expires_in=1)) self.user_info = self.api_client.get_user_info(token.access_token) self.api_client.rest_client.pool_manager.clear() docusign.configuration.api_client = self.api_client envelope_summary = envelopes_api.create_envelope( self.user_info.accounts[0].account_id, envelope_definition=envelope_definition) self.api_client.rest_client.pool_manager.clear() self.envelope_id = envelope_summary.envelope_id except ApiException as e: print("\nException when calling DocuSign API: %s" % e) self.api_client.rest_client.pool_manager.clear()
def dsAuth(): integrator_key = "DOCU-4fcb6bff-70fc-4a48-9fec-2080956f7bcb" base_url = "https://na3.docusign.net/restapi" oauth_base_url = "account.docusign.com" # use account.docusign.com for Live/Production private_key_filename = "C:/Users/kevin.alber/Box Sync/Auto FeedBacker/docusign_private_key.pem" user_id = "d2dc5b01-5dec-45d7-9c3d-b563495dcf3c" # demo user:"******" api_client = docusign.ApiClient(base_url) # IMPORTANT NOTE: # the first time you ask for a JWT access token, you should grant access by making the following call # get DocuSign OAuth authorization url: # oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url) # open DocuSign OAuth authorization url in the browser, login and grant access # webbrowser.open_new_tab(oauth_login_url) # print(oauth_login_url) # END OF NOTE # configure the ApiClient to asynchronously get an access token and store it api_client.configure_jwt_authorization_flow(private_key_filename, oauth_base_url, integrator_key, user_id, 3600) return api_client
from docusign_esign.rest import ApiException user_name = "*****@*****.**" #this value taken from API Username ref. https://admindemo.docusign.com/api-integrator-key user_id = "f3d9588f-4aee-4c2c-8873-d66ea8860ce4" #this value taken from API Username ref. https://admindemo.docusign.com/api-integrator-key integrator_key = "b9182992-b2b4-411b-9aa4-cdbbc3d0c6d9" base_url = "https://demo.docusign.net/restapi" oauth_base_url = "account-d.docusign.com" # use account.docusign.com for Live/Production redirect_uri = "https://www.docusign.com/api" #must register with integrator_key ref. https://support.docusign.com/en/articles/Redirect-URI-not-registered template_id = "40cff443-cbd6-4751-a59a-c1e1d9668b93" template_role_name = 'contract object' private_key_filename = "/home/namgivu/.ssh/namgivu-docusign" #TODO what is this for? ##region authentication api_client = docusign.ApiClient(base_url) # IMPORTANT NOTE: # the first time you ask for a JWT access token, you should grant access by making the following call # get DocuSign OAuth authorization url: oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url) # open DocuSign OAuth authorization url in the browser, login and grant access # webbrowser.open_new_tab(oauth_login_url) print('oauth_login_url=%s' % oauth_login_url) # END OF NOTE # configure the ApiClient to asynchronously get an access token and store it api_client.configure_jwt_authorization_flow(private_key_filename, oauth_base_url, integrator_key,
import time import base64 import docusign_esign as docusign from docusign_esign import EnvelopesApi, ApiException from datetime import datetime, timedelta from ds_config_files import ds_config, aud #from .auth.oauth import OAuthUserInfo, OAuthToken, OAuth, Account, Organization, Link TOKEN_REPLACEMENT_IN_SECONDS = 10 * 60 TOKEN_EXPIRATION_IN_SECONDS = 3600 api_client = docusign.ApiClient() account = None _token_received = None expiresTimestamp = 0 def check_token(): current_time = int(round(time.time())) if not _token_received \ or ((current_time + TOKEN_REPLACEMENT_IN_SECONDS) > expiresTimestamp): update_token() def update_token(): print("Requesting an access token via JWT grant...", end='') private_key_bytes = str.encode(ds_config("DS_PRIVATE_KEY")) token = api_client.request_jwt_user_token( ds_config("DS_CLIENT_ID"), ds_config("DS_IMPERSONATED_USER_GUID"), aud(), private_key_bytes, TOKEN_EXPIRATION_IN_SECONDS) global account
def __init__(self): DsClient.api_client = docusign_esign.ApiClient()
def testRequestASignature(): username = "******" password = "******" integrator_key = "26ec5e49-a531-4457-ab81-163d76f37a17" BASE_URL = "https://demo.docusign.net/restapi" user_id = "39c6e30b-3b99-486f-a671-96acc240d7ab" oauth_base_url = "account-d.docusign.com" # use account.docusign.com for Live/Production api_client = docusign.ApiClient(BASE_URL) redirect_uri = "https://www.docusign.com" private_key_filename = 'private_key2.txt' # IMPORTANT NOTE: # the first time you ask for a JWT access token, you should grant access by making the following call # get DocuSign OAuth authorization url: oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url) # open DocuSign OAuth authorization url in the browser, login and grant access # webbrowser.open_new_tab(oauth_login_url) print(oauth_login_url) # END OF NOTE # configure the ApiClient to asynchronously get an access to token and store it api_client.configure_jwt_authorization_flow(private_key_filename, oauth_base_url, integrator_key, user_id, 3600) docusign.configuration.api_client = api_client # sign_test1_file = "test/docs/SignTest1.pdf" file_contents = open('/Users/lisayoo/Desktop/contract.pdf', 'rb').read() # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = "Hi! Here's your annotated contract." envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # add a document to the envelope doc = docusign.Document() base64_doc = base64.b64encode(file_contents).decode("utf-8") doc.document_base64 = base64_doc doc.name = "test.pdf" doc.document_id = '1' envelope_definition.documents = [doc] # Add a recipient to sign the document signer = docusign.Signer() signer.email = "*****@*****.**" signer.name = 'Kat Wicks' signer.recipient_id = '1' recipients = docusign.Recipients() recipients.signers = [signer] envelope_definition.recipients = recipients envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login(api_password='******', include_account_id_guid='true') assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') api_client.host = base_url docusign.configuration.api_client = api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("EnvelopeSummary: ", end="") print(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def handle_message(message): # server has recieved a message from a client print(message) if (message['type'] == 'coordinates'): petitions = mongo.db.petitions.find_one( {'username': message['username']}) petition = { 'petition_name': message['petition_name'], 'petition_decr': message['petition_name'], 'lng': message['lng'], 'lat': message['lat'] } if petitions: p_list = list(petitions['petitions']) p_list.append(petition) mongo.db.users.update_one({"username": message["username"]}, {"$set": { "petitions": p_list }}) else: p_list = list() p_list.append(petition) print(p_list) mongo.db.petitions.insert_one({"username": message["username"]}, {"petitions": []}) mongo.db.petitions.update_one({"username": message["username"]}, {"$set": { "petitions": p_list }}) elif (message['type'] == 'getPetitions'): room = connectedUsers[message["username"]] all_p = mongo.db.petitions.find() p_list = list() for message in all_p: for petitions in list(message['petitions']): p_list.append(petitions) sendToRoom( socketio, { "type": "gotPetitions", "petitions": json.loads(json_util.dumps(p_list)), "room": room }) elif (message['type'] == 'sendDocument'): user_name = "60d34380-6d41-4fa8-9701-05490acea776" integrator_key = "fe7f0a39-3572-4979-9fa7-79f38d969132" base_url = "https://demo.docusign.net/restapi" oauth_base_url = "account-d.docusign.com" # use account.docusign.com for Live/Production redirect_uri = "https://www.docusign.com/api" private_key_filename = "keys/docusign_private_key.txt" user_id = "60d34380-6d41-4fa8-9701-05490acea776" template_id = "e82be205-2edb-46da-98e6-e9c20417b474" api_client = docusign.ApiClient(base_url) # IMPORTANT NOTE: # the first time you ask for a JWT access token, you should grant access by making the following call # get DocuSign OAuth authorization url: # oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url) # open DocuSign OAuth authorization url in the browser, login and grant access # webbrowser.open_new_tab(oauth_login_url) # END OF NOTE # configure the ApiClient to asynchronously get an access token and store it api_client.configure_jwt_authorization_flow(private_key_filename, oauth_base_url, integrator_key, user_id, 3600) docusign.configuration.api_client = api_client template_role_name = 'test' # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' # assign template information including ID and role(s) envelope_definition.template_id = 'e82be205-2edb-46da-98e6-e9c20417b474' # create a template role with a valid template_id and role_name and assign signer info t_role = docusign.TemplateRole() t_role.role_name = 'test' t_role.name = 'Signer' t_role.email = '*****@*****.**' # create a list of template roles and add our newly created role # assign template role(s) to the envelope envelope_definition.template_roles = [t_role] # send the envelope by setting |status| to "sent". To save as a draft set to "created" envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login(api_password='******', include_account_id_guid='true') assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') api_client.host = base_url docusign.configuration.api_client = api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' print("EnvelopeSummary: ", end="") pprint(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception
def render(): if 'filename' in request.args: user_name = "30c0525d-e78d-4b50-8d1c-ecaaeb951a12" integrator_key = "23e1947d-fd87-4a62-95c4-3c2b0f419d53" base_url = "https://demo.docusign.net/restapi" oauth_base_url = "account-d.docusign.com" # use account.docusign.com for Live/Production redirect_uri = "https://www.docusign.com/api" private_key_filename = "keys/docusign_private_key.txt" user_id = "30c0525d-e78d-4b50-8d1c-ecaaeb951a12" template_id = "31edfa30-c5f8-4802-9beb-5978cac10c74" myfilename = request.args.get('filename') api_client = docusign.ApiClient(base_url) # IMPORTANT NOTE: # the first time you ask for a JWT access token, you should grant access by making the following call # get DocuSign OAuth authorization url: # print(api_client) # print(integrator_key, redirect_uri,oauth_base_url) oauth_login_url = api_client.get_jwt_uri(integrator_key, redirect_uri, oauth_base_url) # open DocuSign OAuth authorization url in the browser, login and grant access # webbrowser.open_new_tab(oauth_login_url) # print(oauth_login_url) # END OF NOTE # configure the ApiClient to asynchronously get an access token and store it # print(private_key_filename) api_client.configure_jwt_authorization_flow(private_key_filename, oauth_base_url, integrator_key, user_id, 3600) # print("test") docusign.configuration.api_client = api_client template_role_name = 'client' # create an envelope to be signed envelope_definition = docusign.EnvelopeDefinition() envelope_definition.email_subject = 'Please Sign my Python SDK Envelope' envelope_definition.email_blurb = 'Hello, Please sign my Python SDK Envelope.' print(envelope_definition) # assign template information including ID and role(s) envelope_definition.template_id = template_id # create a template role with a valid template_id and role_name and assign signer info t_role = docusign.TemplateRole() t_role.role_name = template_role_name t_role.name = 'Pat Developer' t_role.email = "%(filename)s" # # create a list of template roles and add our newly created role # # assign template role(s) to the envelope envelope_definition.template_roles = [t_role] # # send the envelope by setting |status| to "sent". To save as a draft set to "created" envelope_definition.status = 'sent' auth_api = AuthenticationApi() envelopes_api = EnvelopesApi() try: login_info = auth_api.login(api_password='******', include_account_id_guid='true') assert login_info is not None assert len(login_info.login_accounts) > 0 login_accounts = login_info.login_accounts assert login_accounts[0].account_id is not None base_url, _ = login_accounts[0].base_url.split('/v2') api_client.host = base_url docusign.configuration.api_client = api_client envelope_summary = envelopes_api.create_envelope( login_accounts[0].account_id, envelope_definition=envelope_definition) assert envelope_summary is not None assert envelope_summary.envelope_id is not None assert envelope_summary.status == 'sent' # print("EnvelopeSummary: ", end="") # pprint(envelope_summary) except ApiException as e: print("\nException when calling DocuSign API: %s" % e) assert e is None # make the test case fail in case of an API exception return app.send_static_file('index.html', envelope_summary) else: return app.send_static_file('index.html')