Exemplo n.º 1
0
        public static string GetAccountId()
        {
            var    appSettings   = System.Configuration.ConfigurationManager.AppSettings;
            string username      = appSettings["docusignDeveloperEmail"] ?? "*****@*****.**";
            string password      = appSettings["docusignPassword"] ?? "epercic";
            string integratorKey = appSettings["docusignIntegratorKey"] ?? "a2dced5d-bebe-4b70-803e-bbbb70ecf7cb";

            string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";

            Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
            AuthenticationApi authApi   = new AuthenticationApi(Configuration);
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAccount in loginInfo.LoginAccounts)
            {
                if (loginAccount.IsDefault == "true")
                {
                    return(loginAccount.AccountId);
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        public static string GetAccountId()
        {
            var    appSettings   = System.Configuration.ConfigurationManager.AppSettings;
            string username      = appSettings["docusignDeveloperEmail"] ?? "*****@*****.**";
            string password      = appSettings["docusignPassword"] ?? "N#ewport4331";
            string integratorKey = appSettings["docusignIntegratorKey"] ?? "4ed5be53-a1e4-49d4-80bd-563d4635eb9d";

            string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";

            Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
            AuthenticationApi authApi   = new AuthenticationApi(Configuration);
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAccount in loginInfo.LoginAccounts)
            {
                if (loginAccount.IsDefault == "true")
                {
                    return(loginAccount.AccountId);
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public string GetAccountID()
        {
            #region auth_details
            string integratorKey = ConfigurationManager.AppSettings["IntegratorKey"];
            string email         = ConfigurationManager.AppSettings["DocuSignUserEmail"];
            string password      = ConfigurationManager.AppSettings["DocuSignPassword"];

            string authHeader = "{\"Username\":\"" + email + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
            #endregion

            DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            #region attemptlogin
            ApiClient client = new ApiClient(basePath: "https://demo.docusign.net/restapi");
            DocuSign.eSign.Client.Configuration configHeader = new DocuSign.eSign.Client.Configuration(client);
            configHeader.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
            AuthenticationApi authApi = new AuthenticationApi(configHeader);


            LoginInformation loginInfo = authApi.Login();

            #endregion

            return(loginInfo.LoginAccounts[0].AccountId);
        }
Exemplo n.º 4
0
        public void LoginTest()
        {
            // configure the ApiClient for the DocuSign site and authentictaion needed.
            Utils.ConfigureApiClient();


            AuthenticationApi authApi = new AuthenticationApi();

            AuthenticationApi.LoginOptions options = new AuthenticationApi.LoginOptions();
            options.apiPassword          = "******";
            options.includeAccountIdGuid = "true";
            LoginInformation loginInfo = authApi.Login(options);

            Assert.IsNotNull(loginInfo.LoginAccounts);

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    TestConfig.AccountId = loginAcct.AccountId;
                    break;
                }
            }
            Assert.IsNotNull(TestConfig.AccountId);
        }
        public void LegacyLoginTest()
        {
            string authHeader = "{\"Username\":\"" + testConfig.Username + "\", \"Password\":\"" + testConfig.Password + "\", \"IntegratorKey\":\"" + testConfig.IntegratorKey + "\"}";

            testConfig.ApiClient = new ApiClient(testConfig.Host);
            if (testConfig.ApiClient.Configuration.DefaultHeader.ContainsKey("X-DocuSign-Authentication"))
            {
                testConfig.ApiClient.Configuration.DefaultHeader.Remove("X-DocuSign-Authentication");
            }
            testConfig.ApiClient.Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object

            AuthenticationApi authApi   = new AuthenticationApi(testConfig.ApiClient.Configuration);
            LoginInformation  loginInfo = authApi.Login();

            Assert.IsNotNull(loginInfo);
            Assert.IsNotNull(loginInfo.LoginAccounts);

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true" || testConfig.AccountId == null)
                {
                    testConfig.AccountId = loginAcct.AccountId;

                    string[] separatingStrings = { "/v2" };

                    // Update ApiClient with the new base url from login call
                    testConfig.ApiClient = new ApiClient(loginAcct.BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);
                    break;
                }
            }
            Assert.IsNotNull(testConfig.AccountId);
        }
Exemplo n.º 6
0
        public static string GetAccountId()
        {
            var    appSettings   = System.Configuration.ConfigurationManager.AppSettings;
            string username      = appSettings["docusignDeveloperEmail"] ?? "*****@*****.**";
            string password      = appSettings["docusignPassword"] ?? "gopala";
            string integratorKey = appSettings["docusignIntegratorKey"] ?? "TEST-5913deaf-c9d9-4d6b-a8a0-2d7ca76db2f5";

            string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";

            Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
            AuthenticationApi authApi   = new AuthenticationApi(Configuration);
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAccount in loginInfo.LoginAccounts)
            {
                if (loginAccount.IsDefault == "true")
                {
                    return(loginAccount.AccountId);
                }
            }

            return(null);
        }
        public void JwtLoginTest()
        {
            testConfig.ApiClient = new ApiClient(testConfig.Host);
            testConfig.ApiClient.ConfigureJwtAuthorizationFlow(testConfig.IntegratorKey, testConfig.UserId, testConfig.OAuthBasePath, testConfig.PrivateKeyFilename, testConfig.ExpiresInHours);

            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
            AuthenticationApi authApi   = new AuthenticationApi(testConfig.ApiClient.Configuration);
            LoginInformation  loginInfo = authApi.Login();

            Assert.IsNotNull(loginInfo);
            Assert.IsNotNull(loginInfo.LoginAccounts);

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true" || testConfig.AccountId == null)
                {
                    testConfig.AccountId = loginAcct.AccountId;

                    string[] separatingStrings = { "/v2" };

                    // Update ApiClient with the new base url from login call
                    testConfig.ApiClient = new ApiClient(loginAcct.BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);
                    //testConfig.Configuration = config;
                    break;
                }
            }
            Assert.IsNotNull(testConfig.AccountId);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Login this instance.
        /// </summary>
        public static void Login()
        {
            var username      = Settings.Default.Username;
            var password      = Settings.Default.Password;
            var integratorKey = Settings.Default.IntegratorKey;
            var restUrl       = Settings.Default.RestUrl;

            // initialize client for desired environment (for production change to www)
            var apiClient = new ApiClient(restUrl);

            Configuration.Default.ApiClient = apiClient;

            // configure 'X-DocuSign-Authentication' header
            var authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password +
                             "\", \"IntegratorKey\":\"" + integratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // we will retrieve this from the login API call
            string accountId = null;

            /////////////////////////////////////////////////////////////////
            // STEP 1: LOGIN API
            /////////////////////////////////////////////////////////////////

            // login call is available in the authentication api
            var authApi   = new AuthenticationApi();
            var loginInfo = authApi.Login();

            // parse the first account ID that is returned (user might belong to multiple accounts)
            accountId = loginInfo.LoginAccounts[0].AccountId;

            AccountId = accountId;
        }
Exemplo n.º 9
0
        public string loginApi(string usr, string pwd)
        {
            usr = "******";
            pwd = "Cns@12345";
            // we set the api client in global config when we configured the client
            ApiClient apiClient  = Configuration.Default.ApiClient;
            string    authHeader = "{\"Username\":\"" + usr + "\", \"Password\":\"" + pwd + "\", \"IntegratorKey\":\"" + INTEGRATOR_KEY + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
            // we will retrieve this from the login() results
            string accountId = null;
            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (DocuSign.eSign.Model.LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    accountId = loginAcct.AccountId;
                    break;
                }
            }
            if (accountId == null)
            { // if no default found set to first account
                accountId = loginInfo.LoginAccounts[0].AccountId;
            }
            return(accountId);
        }
Exemplo n.º 10
0
        public static string loginApi(string user, string password)
        {
            ApiClient apiClient     = Configuration.Default.ApiClient;
            string    integratorKey = System.Configuration.ConfigurationManager.AppSettings["INTEGRATOR_KEY"];
            string    authHeader    = $"{{\"Username\":\"{user}\",\"Password\":\"{password}\",\"IntegratorKey\":\"{integratorKey}\"}}";

            Configuration.Default.AddDefaultHeader(DocuSignConstants.DocuSignHeader, authHeader);

            string accountId = null;

            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    accountId = loginAcct.AccountId;
                    break;
                }
            }

            if (accountId == null && loginInfo.LoginAccounts.Count > 0)
            {
                accountId = loginInfo.LoginAccounts[0].AccountId;
            }

            return(accountId);
        }
Exemplo n.º 11
0
        public void OAuthAuthorizationCodeFlowTest()
        {
            // Make an API call with the token
            ApiClient apiClient = new ApiClient(BaseUrl);

            DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient;

            // Initiate the browser session to the Authentication server
            // so the user can login.
            string accountServerAuthUrl = apiClient.GetAuthorizationUri(client_id, redirect_url, true, stateOptional);

            System.Diagnostics.Process.Start(accountServerAuthUrl);

            WaitForCallbackEvent = new ManualResetEvent(false);

            // Launch a self-hosted web server to accepte the redirect_url call
            // after the user finishes authentication.
            using (WebApp.Start <Startup>("http://localhost:3000"))
            {
                Trace.WriteLine("WebServer Running. Waiting for access_token...");

                // This waits for the redirect_url to be received in the REST controller
                // (see classes below) and then sleeps a short time to allow the response
                // to be returned to the web browser before the server session ends.
                WaitForCallbackEvent.WaitOne(60000, false);
                Thread.Sleep(1000);
            }
            Assert.IsNotNull(AccessCode);

            string accessToken = apiClient.GetOAuthToken(client_id, client_secret, true, AccessCode);

            Assert.IsNotNull(accessToken);
            Trace.WriteLine("Access_token: " + accessToken);

            // we will retrieve this from the login API call
            string accountId = null;

            /////////////////////////////////////////////////////////////////
            // STEP 1: LOGIN API
            /////////////////////////////////////////////////////////////////

            // login call is available in the authentication api
            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            // parse the first account ID that is returned (user might belong to multiple accounts)
            accountId = loginInfo.LoginAccounts[0].AccountId;

            // Update ApiClient with the new base url from login call
            apiClient = new ApiClient(loginInfo.LoginAccounts[0].BaseUrl);

            /////////////////////////////////////////////////////////////////
            // STEP 2: CREATE ACCOUNTS API
            /////////////////////////////////////////////////////////////////
            AccountsApi        accountsApi        = new AccountsApi();
            AccountInformation accountInformation = accountsApi.GetAccountInformation(accountId);

            Trace.WriteLine(accountInformation.ToString());
        }
Exemplo n.º 12
0
        private void ConfigureApiClientAuth_OldMethod(ApiClient apiClient)
        {
            var username      = this.Configuration["Docusign:username"];
            var password      = this.Configuration["Docusign:password"];
            var integratorKey = this.Configuration["Docusign:clientId"];
            var authHeader    = $"{{\"Username\":\"{username}\", \"Password\":\"{password}\", \"IntegratorKey\":\"{integratorKey}\"}}";

            apiClient.Configuration.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            var authApi = new AuthenticationApi();

            authApi.Login();
        }
Exemplo n.º 13
0
        public void Connect()
        {
            _client = new HttpPilotClient(_settings.ServerUrl);
            _client.Connect(false);

            ServerApi         = _client.GetServerApi(new NullableServerCallback());
            AuthenticationApi = _client.GetAuthenticationApi();
            AuthenticationApi.Login(_settings.DbName, _settings.Login, _settings.Password, false, _settings.LicenseCode);

            var dataBaseInfo = ServerApi.OpenDatabase();

            PersonId = dataBaseInfo.Person.Id;

            FileArchiveApi = _client.GetFileArchiveApi();
        }
        public static string InitializeDocuSignAPI()
        {
            try
            {
                //Get Config settings from App.config
                DocuSignConfig configSettings = new DocuSignConfig();

                string userName      = configSettings.DOCUSIGN_USERNAME;
                string password      = configSettings.DOCUSIGN_PASSWORD;
                string integratorKey = configSettings.DOCUSIGN_IK;

                // initialize client for desired environment (for production change to www)
                ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");
                eSign.Client.Configuration.Default.ApiClient = apiClient;

                // configure 'X-DocuSign-Authentication' header
                string authHeader = "{\"Username\":\"" + userName + "\", \"Password\":\"" + password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
                eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

                // we will retrieve this from the login API call
                string accountId = null;

                // login call is available in the authentication api
                AuthenticationApi authApi   = new AuthenticationApi();
                LoginInformation  loginInfo = authApi.Login();

                // parse the first account ID that is returned (user might belong to multiple accounts)
                accountId = loginInfo.LoginAccounts[0].AccountId;

                // Update ApiClient with the new base url from login call, but separate string to extract the base path
                string   baseUrl   = loginInfo.LoginAccounts[0].BaseUrl;
                string[] separator = new string[] { "/restapi" };
                string   basePath  = baseUrl.Split(separator, StringSplitOptions.None)[0] + "/restapi";
                apiClient = new ApiClient(basePath);

                //IMPORTANT: Reassign apiClient object - if this isn't done, the call will fail in production
                eSign.Client.Configuration.Default.ApiClient = apiClient;

                return(accountId);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw ex;
            }
        }
Exemplo n.º 15
0
        public DocuSignClient(DocuSignCredentials credentials)
        {
            //initialize client for desired environment (for production change to www)
            var apiClient = new ApiClient("https://demo.docusign.net/restapi");

            // configure 'X-DocuSign-Authentication' header
            var authHeader = "{\"Username\":\"" + credentials.Username + "\", \"Password\":\"" + credentials.Password + "\", \"IntegratorKey\":\"" + credentials.IntegratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // login call is available in the authentication api
            var authApi   = new AuthenticationApi();
            var loginInfo = authApi.Login();

            // parse the first account ID that is returned (user might belong to multiple accounts)
            this.AccountId = loginInfo.LoginAccounts[0].AccountId;
        }
Exemplo n.º 16
0
        static void Main(string[] args)
        {
            string username      = "******";
            string password      = "******";
            string integratorKey = "3b9fa7cc-dd91-468a-925d-056ee392643a";

            ApiClient apiClient = new ApiClient("https://demo.docusign.net/restapi");

            Configuration.Default.ApiClient = apiClient;

            string authHeader = "{\"Username\":\"" + username + "\", \"Password\":\"" + password + "\",\"IntegratorKey\":\"" + integratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            string accountid = null;

            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            accountid = loginInfo.LoginAccounts[0].AccountId;

            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "[DocuSign C# SDK] - Sample Signature Request";

            envDef.TemplateId = "";

            TemplateRole tRole = new TemplateRole();

            tRole.Email    = "*****@*****.**";
            tRole.Name     = "Chumani";
            tRole.RoleName = "Junior Developer";

            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            envDef.TemplateRoles = rolesList;

            envDef.Status = "sent";

            EnvelopesApi    envelopesApi    = new EnvelopesApi();
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountid, envDef);
        }
Exemplo n.º 17
0
        // POST api/account/{requestType}/
        public HttpResponseMessage PostRequest(string id, LoginRequest data)
        {
            HttpResponseMessage response;

            switch (id)
            {
            case "login":
                LoginRequest loginRequest = (LoginRequest)data;
                var          isSuccess    = authenticationApi.Login(loginRequest.MobileNo, loginRequest.Password);
                response = Request.CreateResponse(HttpStatusCode.OK, isSuccess);
                break;

            default:
                response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpError("Invalid request type!!!"));
                break;
            }

            return(response);
        }
Exemplo n.º 18
0
        public void Connect()
        {
            _client.Connect();

            ServerApi         = _client.GetServerApi(new NullableServerCallback());
            AuthenticationApi = _client.GetAuthenticationApi();
            AuthenticationApi.Login(_settings.DbName, _settings.Login, _settings.Password, false, 100);
            ServerApi.OpenDatabase();

            var people = ServerApi.LoadPeople();
            var person = people.FirstOrDefault(p => !p.IsDeleted && p.Login == _settings.Login);

            if (person != null)
            {
                PersonId = person.Id;
            }

            FileArchiveApi = _client.GetFileArchiveApi();
        }
Exemplo n.º 19
0
        public DocuSignApiConfiguration SetUp(DocuSignAuthTokenDTO docuSignAuthDTO)
        {
            string baseUrl       = string.Empty;
            string integratorKey = string.Empty;

            //create configuration for future api calls
            if (docuSignAuthDTO.IsDemoAccount)
            {
                integratorKey = CloudConfigurationManager.GetSetting("DocuSignIntegratorKey_DEMO");
                baseUrl       = CloudConfigurationManager.GetSetting("environment_DEMO") + "restapi/";
            }
            else
            {
                integratorKey = CloudConfigurationManager.GetSetting("DocuSignIntegratorKey");
                baseUrl       = docuSignAuthDTO.Endpoint.Replace("v2/accounts/" + docuSignAuthDTO.AccountId.ToString(), "");
            }
            ApiClient     apiClient  = new ApiClient(baseUrl);
            string        authHeader = "bearer " + docuSignAuthDTO.ApiPassword;
            Configuration conf       = new Configuration(apiClient);

            conf.AddDefaultHeader("Authorization", authHeader);
            DocuSignApiConfiguration result = new DocuSignApiConfiguration()
            {
                AccountId = docuSignAuthDTO.AccountId, Configuration = conf
            };

            if (string.IsNullOrEmpty(docuSignAuthDTO.AccountId)) //we deal with and old token, that don't have accountId yet
            {
                AuthenticationApi authApi = new AuthenticationApi(conf);
                try
                {
                    LoginInformation loginInfo = authApi.Login();
                    result.AccountId = loginInfo.LoginAccounts[0].AccountId; //it seems that althought one DocuSign account can have multiple users - only one is returned, the one that oAuth token was created for
                }
                catch (Exception ex)
                {
                    throw new AuthorizationTokenExpiredOrInvalidException();
                }
            }

            return(result);
        }
Exemplo n.º 20
0
        private void GetDocuSignAccountId()
        {
            if (string.IsNullOrWhiteSpace(this.Username) || string.IsNullOrWhiteSpace(this.Password) || string.IsNullOrWhiteSpace(this.IntegratorKey))
            {
                throw new ArgumentException("No se pudo recuperar las credenciales de docuSign");
            }

            // configure 'X-DocuSign-Authentication' header
            var authHeader = "{\"Username\":\"" + this.Username + "\", \"Password\":\"" + this.Password +
                             "\", \"IntegratorKey\":\"" + this.IntegratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // login call is available in the authentication api
            var authApi   = new AuthenticationApi();
            var loginInfo = authApi.Login();

            // parse the first account ID that is returned (user might belong to multiple accounts)
            this.AccountId = loginInfo.LoginAccounts[0].AccountId;
        }
        /// <summary>
        /// Init DocuSign ApiClient
        /// </summary>
        /// <param name="senderUsername"></param>
        /// <param name="senderPassword"></param>
        /// <returns></returns>
        public static LoginInformation GetDocuSignApiClient(string senderUsername, string senderPassword, string senderIntegratorKey)
        {
            //bool loggedIn = loginInfo.LoginAccounts.Where(a => a.UserName == senderUsername && a.ApiPassword == senderPassword)
            if (loginInfo == null)
            {
                var apiClient = new DocuSign.eSign.Client.ApiClient(basePath);
                // set client in global config so we don't need to pass it to each API object
                DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient;
                string authHeader = "{\"Username\":\"" + senderUsername + "\", \"Password\":\"" + senderPassword + "\", \"IntegratorKey\":\"" + senderIntegratorKey + "\"}";
                DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

                //2 the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
                AuthenticationApi authApi = new AuthenticationApi();
                loginInfo = authApi.Login();
            }
            //else
            //    loginInfo.LoginAccounts.Add();

            return(loginInfo);
        }
Exemplo n.º 22
0
        private LoginAccount GetLoginInfo(DocuSignAuthHeader headerOptions)
        {
            var basePath  = "https://demo.docusign.net/restapi";
            var apiClient = new ApiClient(basePath);

            Configuration.Default.ApiClient = apiClient;

            var authHeader = JsonConvert.SerializeObject(headerOptions);

            if (!Configuration.Default.DefaultHeader.ContainsKey("X-DocuSign-Authentication"))
            {
                Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
            }

            var authApi         = new AuthenticationApi();
            var loginInfoResult = authApi.Login();
            var loginInfo       = loginInfoResult.LoginAccounts.First();

            return(loginInfo);
        }
Exemplo n.º 23
0
        private string GetAccountID()
        {
            if (Utility.IsEventLogged)
            {
                Utility.LogAction("Get Account ID");
            }

            string authHeader = "{\"Username\":\"" + _email + "\", \"Password\":\"" + _password + "\", \"IntegratorKey\":\"" + _integratorKey + "\"}";

            DocuSign.eSign.Client.Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            if (Utility.IsEventLogged)
            {
                Utility.LogAction("Auth Login");
            }

            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            return(Utility.DocuSignAccountID = loginInfo.LoginAccounts[0].AccountId);
        }
Exemplo n.º 24
0
        private static void DoLogin()
        {
            string Username      = "******";
            string Password      = "******";
            string IntegratorKey = "068a8288-e7be-466c-9103-31bb707a8cd0";
            // set demo (aka test) environment (for production change to www.docusign.net/restapi)
            string basePath = "https://demo.docusign.net/restapi";
            // instantiate a new api client and set desired environment
            ApiClient apiClient = new ApiClient(basePath);

            // set client in global config so we don't have to pass it to each API object.
            Configuration.Default.ApiClient = apiClient;
            // create JSON formatted auth header containing Username, Password, and Integrator Key
            string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);
            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            Console.WriteLine("LoginInformation: {0}", loginInfo.ToJson());
        }
Exemplo n.º 25
0
        private static Func <BaseRequestModel, string> AuthenticateFunc()
        {
            return(request =>
            {
                Configuration.Default.ApiClient = request.ESignAccount.IsTestApi.HasValue && request.ESignAccount.IsTestApi.Value
                    ? new ApiClient(request.ESignAccount.ApiUrl)
                    : new ApiClient();

                Configuration.Default.DefaultHeader.Clear();
                Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", GetAuthHeader(request.ESignAccount));
                var authApi = new AuthenticationApi();
                var loginInfo = authApi.Login();

                //For Production environment

                /*
                 * As returned by login method, the baseUrl includes the API version and account id. Split the string to obtain the basePath,
                 * just the server name and api name. Eg, you will receive https://na1.docusign.net/restapi/v2/accounts/123123123.
                 * You want just https://na1.docusign.net/restapi
                 * Instantiate the SDK using the basePath. Eg ApiClient apiClient = new ApiClient(basePath);
                 */
                if (!request.ESignAccount.IsTestApi.HasValue || !request.ESignAccount.IsTestApi.Value)
                {
                    var baseURL = loginInfo.LoginAccounts.FirstOrDefault() != null?loginInfo.LoginAccounts.FirstOrDefault().BaseUrl : null;

                    if (!string.IsNullOrEmpty(baseURL))
                    {
                        var sLookFor = "restapi";
                        baseURL = baseURL.Substring(0, baseURL.IndexOf(sLookFor) + sLookFor.Length);
                        Configuration.Default.ApiClient = new ApiClient(baseURL);
                    }
                }

                return loginInfo.LoginAccounts
                .Where(x => x.IsDefault == true.ToString())
                .Select(x => x.AccountId).FirstOrDefault() ?? loginInfo.LoginAccounts[0].AccountId;
            });
        }
Exemplo n.º 26
0
        //Authenticates the user against DocuSign
        public string Login(LoginRequestModel user)
        {
            try
            {
                // Credential come from login form via the LoginRequestModel
                string Username      = user.Username; //[EMAIL]";
                string Password      = user.Password; //[PASSWORD]";
                string integratorKey = GlobalVariables.integratorKey;
                // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi)
                string basePath = "https://demo.docusign.net/restapi";

                // instantiate a new api client
                ApiClient apiClient = new ApiClient(basePath);

                // set client in global config so we don't need to pass it to each API object
                Configuration.Default.ApiClient = apiClient;

                string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + integratorKey + "\"}";
                Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

                // we will retrieve this from the login() results
                string accountId = null;

                // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
                AuthenticationApi authApi   = new AuthenticationApi();
                LoginInformation  loginInfo = authApi.Login();

                // user might be a member of multiple accounts
                accountId = loginInfo.LoginAccounts[0].AccountId;
                //GlobalVariables.LoggedInAccountId = accountId;
                return(accountId);
            }
            catch (Exception e)
            {
                return("Error " + e.Message);
            }
        }
Exemplo n.º 27
0
        static void Main(string[] args)
        {
            // Enter your DocuSign credentials
            string Username      = "******";
            string Password      = "******";
            string IntegratorKey = "[INTEGRATOR_KEY]";

            // specify the document (file) we want signed
            string SignTest1File = @"[PATH/TO/DOCUMENT/TEST.PDF]";

            // Enter recipient (signer) name and email address
            string recipientName  = "[SIGNER_NAME]";
            string recipientEmail = "[SIGNER_EMAIL]";

            // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi)
            string basePath = "https://demo.docusign.net/restapi";

            // instantiate a new api client
            ApiClient apiClient = new ApiClient(basePath);

            // set client in global config so we don't need to pass it to each API object
            Configuration.Default.ApiClient = apiClient;

            string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegratorKey + "\"}";

            Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

            // we will retrieve this from the login() results
            string accountId = null;

            // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
            AuthenticationApi authApi   = new AuthenticationApi();
            LoginInformation  loginInfo = authApi.Login();

            // user might be a member of multiple accounts
            accountId = loginInfo.LoginAccounts[0].AccountId;

            Console.WriteLine("LoginInformation: {0}", loginInfo.ToJson());

            // Read a file from disk to use as a document
            byte[] fileBytes = File.ReadAllBytes(SignTest1File);

            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "[DocuSign C# SDK] - Please sign this doc";

            // Add a document to the envelope
            Document doc = new Document();

            doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes);
            doc.Name           = "TestFile.pdf";
            doc.DocumentId     = "1";

            envDef.Documents = new List <Document>();
            envDef.Documents.Add(doc);

            // Add a recipient to sign the documeent
            Signer signer = new Signer();

            signer.Name        = recipientName;
            signer.Email       = recipientEmail;
            signer.RecipientId = "1";

            // Create a |SignHere| tab somewhere on the document for the recipient to sign
            signer.Tabs = new Tabs();
            signer.Tabs.SignHereTabs = new List <SignHere>();
            SignHere signHere = new SignHere();

            signHere.DocumentId  = "1";
            signHere.PageNumber  = "1";
            signHere.RecipientId = "1";
            signHere.XPosition   = "100";
            signHere.YPosition   = "150";
            signer.Tabs.SignHereTabs.Add(signHere);

            envDef.Recipients         = new Recipients();
            envDef.Recipients.Signers = new List <Signer>();
            envDef.Recipients.Signers.Add(signer);

            // set envelope status to "sent" to immediately send the signature request
            envDef.Status = "sent";

            // Use the EnvelopesApi to send the signature request!
            EnvelopesApi    envelopesApi    = new EnvelopesApi();
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef);

            // print the JSON response
            Console.WriteLine("EnvelopeSummary:\n{0}", JsonConvert.SerializeObject(envelopeSummary));
            Console.Read();
        }
Exemplo n.º 28
0
        /// <summary>
        /// UploadDocuSignEnvelopeToSharePoint - uploads a COMPLETED DocuSign envelope to a Sharepoint folder named as envelopeID
        /// </summary>
        /// <param name="accountID"></param>
        /// <param name="envelopeID"></param>
        static public void UploadDocuSignEnvelopeToSharePoint(string accountID, string envelopeID)
        {
            string userId             = ConfigurationManager.AppSettings["UserId"];
            string oauthBasePath      = ConfigurationManager.AppSettings["OAuthBasePath"];
            string integratorKey      = ConfigurationManager.AppSettings["IntegratorKey"];
            string privateKeyFilename = AppContext.BaseDirectory + "PrivateKey.txt";
            string host           = ConfigurationManager.AppSettings["Host"];
            int    expiresInHours = 1;

            string siteUrl       = ConfigurationManager.AppSettings["SiteUrl"];
            string targetLibrary = ConfigurationManager.AppSettings["TargetLibrary"];
            string userName      = ConfigurationManager.AppSettings["UserName"];
            string password      = ConfigurationManager.AppSettings["Password"];

            ApiClient apiClient = new ApiClient(host);

            apiClient.ConfigureJwtAuthorizationFlow(integratorKey, userId, oauthBasePath, privateKeyFilename, expiresInHours);

            /////////////////////////////////////////////////////////////////
            // STEP 1: LOGIN API
            /////////////////////////////////////////////////////////////////
            AuthenticationApi authApi   = new AuthenticationApi(apiClient.Configuration);
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    accountID = loginAcct.AccountId;

                    string[] separatingStrings = { "/v2" };

                    // Update ApiClient with the new base url from login call
                    apiClient = new ApiClient(loginAcct.BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);
                    break;
                }
            }

            /////////////////////////////////////////////////////////////////
            // STEP 2: GET DOCUMENTS API
            /////////////////////////////////////////////////////////////////

            EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);
            Envelope     envInfo      = envelopesApi.GetEnvelope(accountID, envelopeID);

            if (envInfo.Status.ToLower().CompareTo("completed") == 0)
            {
                // upload all documents for accountID and envelopeID
                MemoryStream docStream = GetAllDocuments(accountID, envelopeID);
                Console.WriteLine("Uploading to SharePoint all documents for envelope {0}", envelopeID);
                string fileName = envInfo.EnvelopeId + ".pdf";
                SharePointOnlineHelper.UploadFileStreamToSharePoint(siteUrl, userName, password, targetLibrary, docStream, fileName, envelopeID, false);

                // upload Certificate of Completion for accountID and envelopeID
                Console.WriteLine("Uploading to SharePoint the Certificate Of Completion for envelope {0}", envelopeID);
                MemoryStream cocStream = GetCertificateOfCompletion(accountID, envelopeID);
                fileName = "COC_" + envInfo.EnvelopeId + ".pdf";
                SharePointOnlineHelper.UploadFileStreamToSharePoint(siteUrl, userName, password, targetLibrary, cocStream, fileName, envelopeID, false);
            }
            else
            {
                Console.WriteLine("Download DocuSign documents can be performed only for COMPLETED envelopes.");
            }
        }
        static string CreateDocuSignEnvelope()
        {
            string userId             = ConfigurationManager.AppSettings["UserId"];
            string oauthBasePath      = ConfigurationManager.AppSettings["OAuthBasePath"];
            string integratorKey      = ConfigurationManager.AppSettings["IntegratorKey"];
            string privateKeyFilename = AppContext.BaseDirectory + "PrivateKey.txt";
            string host           = ConfigurationManager.AppSettings["Host"];
            string templateId     = ConfigurationManager.AppSettings["TemplateID"];
            int    expiresInHours = 1;

            //string accountId = string.Empty;

            ApiClient apiClient = new ApiClient(host);

            apiClient.ConfigureJwtAuthorizationFlow(integratorKey, userId, oauthBasePath, privateKeyFilename, expiresInHours);

            /////////////////////////////////////////////////////////////////
            // STEP 1: LOGIN API
            /////////////////////////////////////////////////////////////////
            AuthenticationApi authApi   = new AuthenticationApi(apiClient.Configuration);
            LoginInformation  loginInfo = authApi.Login();

            // find the default account for this user
            foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
            {
                if (loginAcct.IsDefault == "true")
                {
                    accountID = loginAcct.AccountId;

                    string[] separatingStrings = { "/v2" };

                    // Update ApiClient with the new base url from login call
                    apiClient = new ApiClient(loginAcct.BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);
                    break;
                }
            }

            /////////////////////////////////////////////////////////////////
            // STEP 2: CREATE ENVELOPE API
            /////////////////////////////////////////////////////////////////

            EnvelopeDefinition envDef = new EnvelopeDefinition();

            envDef.EmailSubject = "MS Build Demo - Please sign this doc";

            // assign recipient to template role by setting name, email, and role name.  Note that the
            // template role name must match the placeholder role name saved in your account template.
            TemplateRole tRole = new TemplateRole();

            tRole.Email    = ConfigurationManager.AppSettings["RecipientEmail"];
            tRole.Name     = ConfigurationManager.AppSettings["RecipientName"];
            tRole.RoleName = "Signer";
            List <TemplateRole> rolesList = new List <TemplateRole>()
            {
                tRole
            };

            // add the role to the envelope and assign valid templateId from your account
            envDef.TemplateRoles = rolesList;
            envDef.TemplateId    = templateId;

            // set envelope status to "sent" to immediately send the signature request
            envDef.Status = "sent";

            // |EnvelopesApi| contains methods related to creating and sending Envelopes (aka signature requests)
            EnvelopesApi    envelopesApi    = new EnvelopesApi(apiClient.Configuration);
            EnvelopeSummary envelopeSummary = envelopesApi.CreateEnvelope(accountID, envDef);

            return(envelopeSummary.EnvelopeId);
        }
Exemplo n.º 30
0
        //Method to embed a document signing in a new browser tab
        public ViewUrl SignDocument(ref SignRequestModel signRequest)
        {
            try
            {
                string Username      = signRequest.Username;          //[email]";
                string Password      = signRequest.Password;          //[password]";
                string IntegratorKey = GlobalVariables.integratorKey; //[INTEGRATOR_KEY]";

                // Enter recipient (signer) name and email address
                string recipientName  = signRequest.RecipientName;    //[SIGNER_NAME]";
                string recipientEmail = signRequest.RecipientEmail;   //[SIGNER_EMAIL]";

                // instantiate api client with appropriate environment (for production change to www.docusign.net/restapi)
                string basePath = "https://demo.docusign.net/restapi";

                // instantiate a new api client
                ApiClient apiClient = new ApiClient(basePath);

                // set client in global config so we don't need to pass it to each API object
                Configuration.Default.ApiClient = apiClient;

                string authHeader = "{\"Username\":\"" + Username + "\", \"Password\":\"" + Password + "\", \"IntegratorKey\":\"" + IntegratorKey + "\"}";
                Configuration.Default.AddDefaultHeader("X-DocuSign-Authentication", authHeader);

                // we will retrieve this from the login() results
                string accountId = null;

                // the authentication api uses the apiClient (and X-DocuSign-Authentication header) that are set in Configuration object
                AuthenticationApi authApi   = new AuthenticationApi();
                LoginInformation  loginInfo = authApi.Login();

                // user might be a member of multiple accounts
                accountId = loginInfo.LoginAccounts[0].AccountId;

                //// Use the EnvelopesApi to create and send the signature request
                EnvelopesApi envelopesApi = new EnvelopesApi();

                //Giving the recipient the view.

                RecipientViewRequest viewOptions = new RecipientViewRequest()
                {
                    ReturnUrl            = "https://www.docusign.com/devcenter",
                    ClientUserId         = "1234", // must match clientUserId set in step #2!
                    AuthenticationMethod = "email",
                    UserName             = recipientName,
                    Email = recipientEmail
                };

                // create the recipient view (aka signing URL)
                ViewUrl recipientView = envelopesApi.CreateRecipientView(signRequest.AccountId, signRequest.EnvelopeId, viewOptions);

                // print the JSON response
                //Console.WriteLine("ViewUrl:\n{0}", JsonConvert.SerializeObject(recipientView));

                // Start the embedded signing session!
                return(recipientView);
            }
            catch (Exception e)
            {
                signRequest.Message = e.Message;
                return(null);
            }
        }