Saturday, August 25, 2018

Docusign GO Live



Docusign go-live process is very confusing. Here are the steps below to make review pass using the JAVA SDK API calls.
Create a maven project with the following dependency.

import java.awt.Desktop;
import java.net.URI;
import java.util.List;

import org.apache.oltu.oauth2.common.token.BasicOAuthToken;

import com.docusign.esign.api.AuthenticationApi;
import com.docusign.esign.api.EnvelopesApi;
import com.docusign.esign.client.ApiClient;
import com.docusign.esign.client.Configuration;
import com.docusign.esign.client.auth.AccessTokenListener;
import com.docusign.esign.model.Envelope;
import com.docusign.esign.model.EnvelopesInformation;
import com.docusign.esign.model.LoginInformation;

public class DocusignTest {

    private static final String CODE = "";
    private static final String TOKEN = "";

    public static void main(String[] args) throws Exception {

        boolean getCode = false;
        boolean update = false;

        String integratorKey = "your integrator key which you want to promote ";
        String clientSecret = "your secret key";

        String redirectURL = "your redirect url";
        String authServerUrl = "https://account-d.docusign.com";
        String restApiUrl = "https://demo.docusign.net/restapi";

        ApiClient apiClient = new ApiClient(authServerUrl, "docusignAccessCode", integratorKey, clientSecret);
        apiClient.setBasePath(restApiUrl);
        apiClient.configureAuthorizationFlow(integratorKey, clientSecret, redirectURL);
        Configuration.setDefaultApiClient(apiClient);

        if (getCode) {
            String oauthLoginUrl = apiClient.getAuthorizationUri();
            Desktop.getDesktop().browse(URI.create(oauthLoginUrl));
        } else {

            apiClient.getTokenEndPoint().setCode(CODE);
            apiClient.registerAccessTokenListener(new AccessTokenListener() {
                @Override
                public void notify(BasicOAuthToken token) {
                    System.out.println("Got a fresh token: " + token.getAccessToken());
                }
            });

            if (update) {
                apiClient.updateAccessToken();
                System.out.println(apiClient.getAccessToken());
            } else {
                apiClient.setAccessToken(TOKEN, 28800l);
                String accountId = getBaseUri(apiClient);

                EnvelopesApi envelopesApi = new EnvelopesApi(apiClient);
                EnvelopesApi.ListStatusChangesOptions options = envelopesApi.new ListStatusChangesOptions();
                String date = "May 22, 2018";
                options.setFromDate(date);
                EnvelopesInformation envelopes = envelopesApi.listStatusChanges(accountId, options);

                List<Envelope> envelopes1 = envelopes.getEnvelopes();
                for (Envelope envelope : envelopes1) {
                    EnvelopesApi envelopesApi1 = new EnvelopesApi();
                    Envelope env = envelopesApi1.getEnvelope(accountId, envelope.getEnvelopeId());
                    System.out.println(env.getEnvelopeId());
                    Thread.sleep(2000);
                }
            }

        }

    }

    public static String getBaseUri(ApiClient apiClient) {
        try {
            AuthenticationApi authApi = new AuthenticationApi(apiClient);
            LoginInformation loginInfo = authApi.login();
            String accountId = loginInfo.getLoginAccounts().get(0).getAccountId();
            String baseUrl = loginInfo.getLoginAccounts().get(0).getBaseUrl();
            String[] accountDomain = baseUrl.split("/v2");
            apiClient.setBasePath(accountDomain[0]);
            Configuration.setDefaultApiClient(apiClient);
            return accountId;
        } catch (Exception ex) {
            System.out.println("Error: " + ex);
            return null;
        }
    }
}
Fill all the fields "redirectURL", "integratorKey" and "clientSecret".

First, run the program by setting getCode=true;

Now copy the code from your redirect URL in the browser and assign it to "CODE" constant field.

Now make getCode = false and make update=true;

Now run and you see the "token" in the console. Copy that and assign it to the TOKEN constant field.

Now run the Program again by making update=false. If you make 20+ successful transactions ( like getting the 20+ different envelopes), your review should pass.


Wednesday, August 15, 2018

Enabling HTTPS for your Angular-Spring Website




To enable HTTPS for your website you’ll need to get and configure the required SSL/TLS certificates on your server. Start with choosing a trusted certificate provider. There are many authorities who give certificate free for 90 days. "Let’s Encrypt" is most popular open Certificate Authority. "SSL for free" issues certificates using "Let’s Encrypt"


1. Go to SSL FOR FREE

2. Enter your website to secure ( IP address do not work, you have to enter a registered domain name )

3. Select Manual Verification ( DNS ) option



4. Manually verify Domain



5. Go into the DNS management page that your domain and add TXT records with given key and value.



6. Now download SSL certificate.



The downloaded archive will have a certificate, bundle, and key. Extract the zip file and copy certificate and key to your ubuntu server.

Now you have to install this certificate in client and server.

Client Installation.

For the angular client, you need to add the following options to ng serve command in the package.json

--port 443 --disableHostCheck true --ssl --ssl-cert /home/ubuntu/certificate.crt --ssl-key /home/ubuntu/private.key

Note that port is 443. You have to open the port 443 in your security Group/ Firewall.
"scripts": { "ng": "ng", "start": "ng serve --host 0.0.0.0", "build": "ng build --prod", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }

Restart client.

Server Installation.

This tutorial assumes that your server is Java Spring Boot.
You need to generate a key store for the server.
openssl pkcs12 -export -in certificate.crt -inkey private.key -out keystore.p12 -name server

This above step will ask for a password. Please enter the password and remember it.

Go to application.properties file and add following key value pairs.
server.port: 8443 server.ssl.key-store: keystore.p12 server.ssl.key-store-password: <your_password> server.ssl.keyStoreType: PKCS12 server.ssl.keyAlias: server Now clean buid and restart the server.

For python Flask Server.

from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": app.run(host='0.0.0.0',ssl_context=('/home/ubuntu/certificate.crt', '/home/ubuntu/private.key')) port is 5000 by default.

Now you can access your website using https://your-domain.com

Also, import the certificate to java trust store.

Import to trust store :
keytool -import -alias server -keystore /usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts -file /home/ubuntu/certificate.crt

To know your java home on ubuntu

readlink -f /usr/bin/java | sed "s:bin/java::"

$(readlink -f /usr/bin/java | sed "s:bin/java::")lib/security/cacerts