> For the complete documentation index, see [llms.txt](https://docs.conscent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.conscent.ai/version-1.0/auto-login.md).

# Auto Login

## A temporary token is generated using an API and this token needs to be stored at Client's end.

<mark style="color:green;">`POST`</mark> `{API_URL}/client/generate-temp-token`

**Authorization:**

Client API Key and API Secret must be passed in Authorization Headers using Basic Auth. With API Key as the Username and API Secret as the password.

#### Request Body

| Name                                          | Type   | Description              |
| --------------------------------------------- | ------ | ------------------------ |
| email<mark style="color:red;">\*</mark>       | String | email of the user        |
| phoneNumber<mark style="color:red;">\*</mark> | String | phone number of the user |
| clientId<mark style="color:red;">\*</mark>    | String | Client Id of the client  |

{% tabs %}
{% tab title="200: OK { "tempAuthToken": "644a2c13ce90df4882d1787a" }" %}

{% endtab %}
{% endtabs %}

> You need to pass either the phone number or email of the user from which they have made the purchase.

{% tabs %}
{% tab title="shell" %}

```sh
 csc('auto-login', {
      clientId: clientId,
      token: tokenEntered,
      phone: data?.phoneNumber,
      email: data?.email,
      successCallbackFunction: async (userDetailsObject: any) => {
        setShowLoginDetails(true);
        console.log('Success callback received from conscent auto Login', userDetailsObject);
        alert('login successfull');
      },
      errorCallbackFunction: (errorObject: any) => {
        console.error(errorObject);
        alert('login unsuccessfull');
      },
      unauthorizedCallback: () => {
        console.log('unauthorized callback called');
      },
    });
```

{% endtab %}

{% tab title="javaScript" %}

```javascript
csc('auto-login', {
      clientId: clientId,
      token: tokenEntered,
      phone: data?.phoneNumber,
      email: data?.email,
      successCallbackFunction: async (userDetailsObject: any) => {
        setShowLoginDetails(true);
        console.log('Success callback received from conscent auto Login', userDetailsObject);
        alert('login successfull');
      },
      errorCallbackFunction: (errorObject: any) => {
        console.error(errorObject);
        alert('login unsuccessfull');
      },
      unauthorizedCallback: () => {
        console.log('unauthorized callback called');
      },
    });
```

{% endtab %}

{% tab title="php" %}

```php
csc('auto-login', {
      clientId: clientId,
      token: tokenEntered,
      phone: data?.phoneNumber,
      email: data?.email,
      successCallbackFunction: async (userDetailsObject: any) => {
        setShowLoginDetails(true);
        console.log('Success callback received from conscent auto Login', userDetailsObject);
        alert('login successfull');
      },
      errorCallbackFunction: (errorObject: any) => {
        console.error(errorObject);
        alert('login unsuccessfull');
      },
      unauthorizedCallback: () => {
        console.log('unauthorized callback called');
      },
    });
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
ConscentWrapper.INSTANCE?.autoLogin(
                        phoneNumber = phoneNumber,
                        email = email,
                        clientActivity = this@LoginActivity,
                        tempToken = token
                    )
```

* The below code is a callback handler that gives a response in boolean format either **true** or **false**.
* **True** is defined as Login successful.
* **False** is defined as Login failed.

```kotlin
 override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        Log.i(TAG, "RedirectionHandler.onActivityResult: ")
        if (resultCode == RESULT_OK) {
            Toast.makeText(applicationContext,"${data?.getStringExtra("STATUS")}",Toast.LENGTH_LONG).show()
        }
    }
```

{% endtab %}
{% endtabs %}
