Пример #1
0
        private static DocuSignAccount GetDocuSignAccount(OAuth20Token token)
        {
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            var userInfoString = RequestHelper.PerformRequest(DocuSignLoginProvider.DocuSignHost + "/oauth/userinfo",
                                                              headers: new Dictionary <string, string> {
                { "Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token) }
            });

            Log.Debug("DocuSing userInfo: " + userInfoString);

            var userInfo = (DocuSignUserInfo)JsonConvert.DeserializeObject(userInfoString, typeof(DocuSignUserInfo));

            if (userInfo.Accounts == null || userInfo.Accounts.Count == 0)
            {
                throw new Exception("Account is null");
            }

            var account = userInfo.Accounts[0];

            return(account);
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (CoreContext.UserManager.GetUsers(SecurityContext.CurrentAccount.ID).IsVisitor() ||
                    !FilesSettings.EnableThirdParty || !ImportConfiguration.SupportDocuSignInclusion)
                {
                    throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
                }

                var error = Request["error"];
                if (!string.IsNullOrEmpty(error))
                {
                    if (error == "access_denied")
                    {
                        error = "Canceled at provider";
                    }
                    throw new Exception(error);
                }

                OAuth20Token token;

                var code = Request["code"];
                if (!string.IsNullOrEmpty(code))
                {
                    token = DocuSignLoginProvider.GetAccessToken(code);
                    DocuSignHelper.ValidateToken(token);
                    DocuSignToken.SaveToken(token);
                }
                else
                {
                    token = DocuSignToken.GetToken();
                    if (token == null)
                    {
                        OAuth20TokenHelper.RequestCode(HttpContext.Current,
                                                       DocuSignLoginProvider.DocuSignOauthCodeUrl,
                                                       DocuSignLoginProvider.DocuSignOAuth20ClientId,
                                                       DocuSignLoginProvider.DocuSignOAuth20RedirectUrl,
                                                       DocuSignLoginProvider.DocuSignScope);
                        return;
                    }
                }

                SubmitToken("", Source);
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Global.Logger.Error("DocuSign", ex);
                SubmitError(ex.Message, Source);
            }
        }
Пример #3
0
        public static string SendDocuSign(object fileId, DocuSignData docuSignData, Dictionary <string, string> requestHeaders)
        {
            if (docuSignData == null)
            {
                throw new ArgumentNullException("docuSignData");
            }
            var token   = DocuSignToken.GetToken();
            var account = GetDocuSignAccount(token);

            var  configuration = GetConfiguration(account, token);
            File sourceFile;
            var  document = CreateDocument(fileId, docuSignData.Name, docuSignData.FolderId, out sourceFile);

            var url = CreateEnvelope(account.AccountId, document, docuSignData, configuration);

            FilesMessageService.Send(sourceFile, requestHeaders, MessageAction.DocumentSendToSign, "DocuSign", sourceFile.Title);

            return(url);
        }
Пример #4
0
        private static DocuSignOrigin.Client.Configuration GetConfiguration(DocuSignAccount account, OAuth20Token token)
        {
            if (account == null)
            {
                throw new ArgumentNullException("account");
            }
            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            var apiClient = new ApiClient(account.BaseUri + "/restapi");

            var configuration = new DocuSignOrigin.Client.Configuration {
                ApiClient = apiClient
            };

            configuration.AddDefaultHeader("Authorization", "Bearer " + DocuSignToken.GetRefreshedToken(token));

            return(configuration);
        }
Пример #5
0
        public static File SaveDocument(string envelopeId, string documentId, string documentName, object folderId)
        {
            if (string.IsNullOrEmpty(envelopeId))
            {
                throw new ArgumentNullException("envelopeId");
            }
            if (string.IsNullOrEmpty(documentId))
            {
                throw new ArgumentNullException("documentId");
            }

            var token         = DocuSignToken.GetToken();
            var account       = GetDocuSignAccount(token);
            var configuration = GetConfiguration(account, token);

            using (var fileDao = Global.DaoFactory.GetFileDao())
                using (var folderDao = Global.DaoFactory.GetFolderDao())
                {
                    if (string.IsNullOrEmpty(documentName))
                    {
                        documentName = "new.pdf";
                    }

                    Folder folder;
                    if (folderId == null ||
                        (folder = folderDao.GetFolder(folderId)) == null ||
                        folder.RootFolderType == FolderType.TRASH ||
                        !Global.GetFilesSecurity().CanCreate(folder))
                    {
                        if (Global.FolderMy != null)
                        {
                            folderId = Global.FolderMy;
                        }
                        else
                        {
                            throw new SecurityException(FilesCommonResource.ErrorMassage_SecurityException_Create);
                        }
                    }

                    var file = new File
                    {
                        FolderID = folderId,
                        Comment  = FilesCommonResource.CommentCreateByDocuSign,
                        Title    = FileUtility.ReplaceFileExtension(documentName, ".pdf"),
                    };

                    var envelopesApi = new EnvelopesApi(configuration);
                    Log.Info("DocuSign webhook get stream: " + documentId);
                    using (var stream = envelopesApi.GetDocument(account.AccountId, envelopeId, documentId))
                    {
                        file.ContentLength = stream.Length;
                        file = fileDao.SaveFile(file, stream);
                    }

                    FilesMessageService.Send(file, MessageInitiator.ThirdPartyProvider, MessageAction.DocumentSignComplete, "DocuSign", file.Title);

                    FileMarker.MarkAsNew(file);

                    return(file);
                }
        }