Skip to navigation

How to log in to Docusign from your app

View as Markdown

This topic demonstrates how to log in to Docusign from your app.

Required data

Running the code in this how-to requires this data:

Data elementDescription
{API_ACCOUNT_ID}A GUID value that identifies your account. This value is automatically generated by Docusign for any account you create. Copy the value from the API Account ID field on the Apps and Keys page.
{BASE_PATH}A string value that forms the root of the URL required to make API calls. The base path value in the example code is set to target the developer environment at
https://<domain>/restapi
Where <domain> is demo.docusign.net for the developer environment and is the result of the GetUserInfo call in production.
{CLIENT_SECRET}The secret key that is associated with the integration key for your app. This value can be created in the Apps and Keys page. See secret key for details.
{INTEGRATION_KEY}A GUID value that identifies your app. This can be obtained in your developer account by accessing the Apps and Keys page. See the Administration Guide for more information.
{REDIRECT_URI}A URL to which the user will be forwarded after authentication. The value for this URL must exactly match one of those pre-registered for the integration key in your Docusign account. See redirect URI for details.

Step 1. Obtain your OAuth token

To make the API call shown in this how-to, you need a valid OAuth access token. The Docusign Android SDK supports access tokens for two different OAuth grant types: Authorization Code Grant and JSON Web Token (JWT) Grant. Choose the OAuth grant type appropriate for your scenario. See Authenticate for guidance on your options to get an OAuth token.

Three icons that represent the three methods a user can use to obtain an OAuth token: JSON Web Token (JWT), Public Authorization Code Grant (ACG), and Confidential Authorization Code grant

Step 2. Initialize a Docusign instance

Use the method shown to initialize a Docusign instance. Call this from the onCreate() method in your Application class.

Note: This how-to initializes a Docusign instance for the developer environment. For production, use DSEnvironment.PRODUCTION_ENVIRONMENT.

try {
DocuSign.init(
context, // the Application Context
“{INTEGRATION_KEY}”,
“{CLIENT_SECRET}”,
“{REDIRECT_URI}”,
DSMode.DEBUG
);
DocuSign.getInstance().setEnvironment(DSEnvironment.DEMO_ENVIRONMENT);
} catch (DSException e) {
e.printStackTrace();
}

Step 3. Log in to Docusign

Use the method shown to log in to Docusign. Be sure to substitute {ACCESS_TOKEN} for the token obtained in Step 1.

try {
DSAuthenticationDelegate docusignAuthDelegate = DocuSign.getInstance().getAuthenticationDelegate();
int expiresIn = 3600; //The number of seconds before the access token expires.
docusignAuthDelegate.login("{ACCESS_TOKEN}",
null, //refresh token
expiresIn,
context,
new DSAuthenticationListener() {
@Override
public void onSuccess(DSUser dsUser) {
Log.d("login", "Successfully Logged in");
}
@Override
public void onError(DSAuthenticationException exception) {
Log.e("login", exception.getLocalizedMessage());
}
}, "{ACCOUNT_ID}"
);
} catch (DocuSignNotInitializedException exception) {
Log.e("login", "DocuSign not initialized exception: " + exception.getLocalizedMessage());
}

Expected response

If your login is successful, the onSuccess method in the listener defined in Step 3 will be triggered, and a DSUser object is returned. You will now be able to make API calls.

Next steps