# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.conscent.ai/version-1.0/auto-login.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
