Signing

Use artifacts to secure document orders

362 views August 3, 2017 October 9, 2017 3

[TestMethod]
public async Task Use_artifact_authentication_to_allow_the_user_to_sign_immediately_without_authentication()
{
    sdsdocument uploadedDocument = await UploadDocument();
    createrequestrequest request = GetCreateRequest(uploadedDocument);
    request.request[0].task[0].subject = GetSubject();
    request.request[0].task[0].authentication = new authentication
    {
        // The artifact will be returned in the response
        // and must be appended to the URL
        artifact = true,
        artifactSpecified = true,
    };
    createrequestresponse response;
    using (var client = new DocumentEndPointClient())
    {
        response = client.createRequest(request);
    }
    String signHereUrl =
        String.Format("https://preprod.signicat.com/std/docaction/demo?request_id={0}&task_id={1}", response.requestid[0], request.request[0].task[0].id);

    // Append the artifact.
    // The document can not be viewed or signed
    // without an artifact in the URL.
    signHereUrl += "&artifact=" + response.artifact;

    Console.WriteLine(signHereUrl);
    Assert.IsNotNull(response);
    Assert.IsNotNull(response.artifact);
    Assert.IsNotNull(response.requestid);
}

private async Task<sdsdocument> UploadDocument()
{
    var httpClientHandler = new HttpClientHandler { Credentials = new NetworkCredential("demo", "Bond007") };
    using (var client = new HttpClient(httpClientHandler))
    {
        HttpContent content = new ByteArrayContent(File.ReadAllBytes("demo_avtale.pdf"));
        content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");
        HttpResponseMessage response = await client.PostAsync("https://preprod.signicat.com/doc/demo/sds", content);
        string documentId = await response.Content.ReadAsStringAsync();
        return new sdsdocument
        {
            id = "doc_1",
            refsdsid = documentId,
            description = "Terms and conditions"
        };
    }
}

private subject GetSubject()
{
    return new subject
    {
        id = "subj_1", // Any identifier you'd like
        nationalid = "1909740939" // CPR, personnummer, fødselsnummer etc.
    };
}

private createrequestrequest GetCreateRequest(sdsdocument documentInSds)
{
    var request = new createrequestrequest
    {
        password = "Bond007",
        service = "demo",
        request = new request[]
         {
             new request
             {
                 clientreference = "cliref1",
                 language = "da",
                 profile = "demo",
                 document = new document[]
                 {
                     documentInSds
                 },
                 task = new task[]
                 {
                     new task
                     {
                         id = "task_1", // Any identifier you'd like
                         subjectref = "subj_1", // Any identifier you'd like
                         documentaction = new documentaction[]
                         {
                              new documentaction
                              {
                                  type = documentactiontype.sign, // Sign or View
                                  documentref = "doc_1" // Any identifier you'd like
                              }
                         },
                         signature = new signature[]
                         {
                             new signature
                             {
                                 method = new string[]
                                 {
                                     // The name of the signature method(s)
                                     "nemid-sign"
                                 }
                             }
                         }
                     }
                 }
             }
         }
    };
    return request;
}
package com.signicat.signature;

import com.signicat.document.v2.*;
import org.apache.http.client.fluent.Executor;
import org.apache.http.entity.ContentType;
import org.junit.Assert;
import org.junit.Test;

import javax.xml.ws.Service;
import java.io.File;
import java.io.IOException;

public class UseArtifactsToSecureOrders {
	@Test
	public void use_artifact_authentication_to_allow_the_user_to_sign_immediately_without_authentication() throws Exception {
		SdsDocument uploadedDocument = uploadDocument();
		CreateRequestRequest request = getCreateRequest(uploadedDocument);
		request.getRequest().get(0).getTask().get(0).setSubject(getSubject());

		Authentication authentication = new Authentication();
		authentication.setArtifact(true); // The artifact will be returned in the response and must be appended to the URL
		request.getRequest().get(0).getTask().get(0).setAuthentication(authentication);

		Service documentService = new DocumentService();
		DocumentEndPoint client = documentService.getPort(DocumentEndPoint.class);
		CreateRequestResponse response = client.createRequest(request);

		String signHereUrl =
				String.format("https://preprod.signicat.com/std/docaction/demo?request_id=%s&task_id=%s",
						response.getRequestId().get(0), request.getRequest().get(0).getTask().get(0).getId());

		signHereUrl += "&artifact=" + response.getArtifact();
		System.out.println(signHereUrl);
		Assert.assertNotNull(response);
		Assert.assertNotNull(response.getArtifact());
		Assert.assertNotNull(response.getRequestId());
	}

	private SdsDocument uploadDocument() throws IOException {
		org.apache.http.client.fluent.Request request = org.apache.http.client.fluent.Request
				.Post("https://preprod.signicat.com/doc/demo/sds")
				.bodyFile(new File("src/test/resources/demo_avtale.pdf"), ContentType.create("application/pdf"));
		String documentId = Executor.newInstance()
				.auth("demo", "Bond007")
				.execute(request)
				.returnContent().asString();

		SdsDocument sdsDocument = new SdsDocument();
		sdsDocument.setId("doc_1");
		sdsDocument.setRefSdsId(documentId);
		sdsDocument.setDescription("Terms and conditions");
		return sdsDocument;
	}


	public Subject getSubject() {
		Subject subject = new Subject();
		subject.setId("subj_1"); // Any identifier you'd like
		subject.setNationalId("1909740939"); // CPR, personnummer, f?dselsnummer etc.
		return subject;
	}

	private CreateRequestRequest getCreateRequest(SdsDocument documentInSds) {
		CreateRequestRequest createRequestRequest = new CreateRequestRequest();
		createRequestRequest.setService("demo");
		createRequestRequest.setPassword("Bond007");

		Request request = new Request();
		request.setClientReference("cliref1");
		request.setLanguage("da");
		request.setProfile("demo");

		request.getDocument().add(documentInSds);

		Task task = new Task();
		task.setId("task_1"); // Any identifier you'd like
		task.setSubjectRef("subj_1"); // Any identifier you'd like
		task.setBundle(false);

		DocumentAction documentAction = new DocumentAction();
		documentAction.setType(DocumentActionType.SIGN); // Sign or View
		documentAction.setDocumentRef("doc_1"); // Any identifier you'd like
		task.getDocumentAction().add(documentAction);

		Signature signature = new Signature();
		signature.getMethod().add("nemid-sign"); // The name of the signature method(s)
		task.getSignature().add(signature);

		request.getTask().add(task);

		createRequestRequest.getRequest().add(request);
		return createRequestRequest;
	}
}

Was this helpful?