Пример #1
0
        public void OnGet()
        {
            var requestedTemplate = HttpContext.Session.GetString(LingkConst.SessionKey);

            if (requestedTemplate == null)
            {
                ErrorMessage = "Please correct the url to create the envelope eg. /adddrop";
                return;
            }
            selectedEnvelope = LingkYaml.LingkYamlConfig.Envelopes.Where(env =>
                                                                         env.Url.ToLower() == requestedTemplate.ToLower()
                                                                         ).FirstOrDefault();
            if (selectedEnvelope == null)
            {
                ErrorMessage = requestedTemplate + " url does not exists in yaml configuration";
                return;
            }
            this.lingkCredentials = DocusignHelper.GetAccessToken(LingkYaml.LingkYamlConfig.LingkProject);
            if (lingkCredentials.credentialsJson.accountId == null)
            {
                ErrorMessage = "You don't have access for the account " + lingkCredentials.credentialsJson.accountId;
                return;
            }
            ErrorMessage = null;
            accountId    = lingkCredentials.credentialsJson.accountId;
            templateId   = selectedEnvelope.Template;

            var name         = GetClaimsByType("name");//This is to add signer
            var emailAddress = GetClaimsByType("emailaddress");

            Url = CreateURL(emailAddress, name, emailAddress, name);
        }
Пример #2
0
        public static LingkCredentials GetAccessToken(LingkProject lingkProject)
        {
            if (lingkCredentials == null || ExpireIn == null || DateTime.Now.Subtract(TimeSpan.FromMinutes(3)) > ExpireIn.Value)
            {
                var resp = LingkHelper.LingkServicecall(lingkProject);

                var lingkDocusign = JsonConvert.DeserializeObject <LingkDocusign>(resp.Result);

                if (lingkDocusign.errorCode != null)
                {
                    throw new Exception(lingkDocusign.errorCode + ":" + lingkDocusign.errorDescription
                                        + "," + lingkDocusign.errorMetadata);
                }
                var jwtGrant = new JwtGrant
                {
                    grant_type = LingkConst.DocuSignGrantType,
                    assertion  = lingkDocusign.credentialsJson.JWT
                };

                var client  = new RestClient(lingkDocusign.credentialsJson.isSandbox ? LingkConst.DocusignDemoAuthUrl : LingkConst.DocusignProdAuthUrl);
                var request = new RestRequest(Method.POST);
                request.AddHeader("content-type", "application/json");
                request.AddHeader("cache-control", "no-cache");
                request.AddParameter("application/json", JsonConvert.SerializeObject(jwtGrant), ParameterType.RequestBody);
                IRestResponse responseData = client.Execute(request);
                var           authToken    = JsonConvert.DeserializeObject <Token>(responseData.Content);
                if (authToken.error != null)
                {
                    throw new Exception(authToken.error_description + " not able to generate access_token from jwt ");
                }
                ExpireIn         = DateTime.Now.AddSeconds(authToken.expires_in);
                lingkCredentials = new LingkCredentials
                {
                    credentialsJson = lingkDocusign.credentialsJson,
                    docuSignToken   = authToken
                };
            }
            return(lingkCredentials);
        }