> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# How to log in to Docusign from your app

> Learn how to log in to Docusign from your Android app.

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 element       | Description                                                                                                                                                                                                                                                                                                                                                                                                    |
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \{API_ACCOUNT_ID}  | A [GUID](http://guid.one/) 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](https://admindemo.docusign.com/authenticate?goTo=appsAndKeys) 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](/platform/configure-app#integration-key) for your app. This value can be created in the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=appsAndKeys) page. See [secret key](/platform/configure-app#secret-key) for details.                                                                                                     |
| \{INTEGRATION_KEY} | A [GUID](http://guid.one/) value that identifies your app. This can be obtained in your developer account by accessing the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=appsAndKeys) page. See the [Administration Guide](https://support.docusign.com/s/document-item?language=en_US\&rsc_301\&bundleId=pik1583277475390\&topicId=pmp1583277397015.html&_LANG=enus) 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](/platform/configure-app#integration-key) in your Docusign account. See [redirect URI](/platform/configure-app#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](/platform/auth) 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](/_fern-files/_img/64f473773042ee439449a096bf7673292b1585b86a4ccc55f82ba0dda41f61a1.webp)

## Step 2. Initialize a Docusign instance

Use the method shown to initialize a [Docusign](https://docusign.github.io/mobile-android-sdk/sdk/com.docusign.androidsdk/-docu-sign/index.html) instance. Call this from the `onCreate()` method in your [Application](https://developer.android.com/reference/android/app/Application) class.

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

**`Java`**

```java title="Java"
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();
}
```

**`Kotlin`**

```kotlin title="Kotlin"
try {
    DocuSign.init(
        context,  // the Application Context
        “{INTEGRATION_KEY}”,
        “{CLIENT_SECRET}”,
        “{REDIRECT_URI}”,
        DSMode.DEBUG
    )
    DocuSign.getInstance().setEnvironment(DSEnvironment.DEMO_ENVIRONMENT) //
} catch (e: DSException) {
    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.

**`Java`**

```java title="Java"
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());
}
```

**`Kotlin`**

```kotlin title="Kotlin"
try {
    val docusignAuthDelegate = DocuSign.getInstance().getAuthenticationDelegate()
    val expiresIn = 3600 //The number of seconds before the access token expires.
    docusignAuthDelegate.login(
        "{ACCESS_TOKEN}",
        null, //refresh token
        expiresIn,
        context,
        object : DSAuthenticationListener {
            override fun onSuccess(dsUser: DSUser) {
                Log.d("login", "Successfully Logged in")
            }

            override fun onError(e: DSAuthenticationException) {
                Log.e("login", "Failed to Log in")
            }
        },
        "{ACCOUNT_ID}"
    )
} catch (exception: DocuSignNotInitializedException) {
    Log.e("login", "DocuSign not initialized exception: " + exception.localizedMessage)
}
```

## Expected response

If your login is successful, the `onSuccess` method in the listener defined in Step 3 will be triggered, and a [DSUser](https://docusign.github.io/mobile-android-sdk/sdk-common/com.docusign.androidsdk.dsmodels/-d-s-user/index.html) object is returned. You will now be able to make API calls.

## Next steps

* Learn [How to request a signature online (embedded signing)](/docs/mobile-sdks/android-sdk/how-to/request-signature-embedded).
* See [How to start the signing process for an unsigned envelope without connectivity (offline)](/docs/mobile-sdks/android-sdk/how-to/start-signing-offline).
* Learn [How to cache an existing unsigned envelope to use offline](/docs/mobile-sdks/android-sdk/how-to/cache-envelope).