> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Application of Plain-Text Authentication Policy to REST API via LDAP Provider

> Explains how to apply Plain-Text Authentication policy to Swagger Petstore REST API via LDAP/Active Directory provider. Includes all steps from establishing LDAP connection to authentication settings, adding policy to testing.

The numbering in the diagram below corresponds to the **order of operations**.

* **Security Manager** in **Apinizer** requests **Plain-Text type authentication** information from **API Client**.
* **Authentication** information is sent to be checked via LDAP.
* **LDAP** returns a response to Apinizer regarding authentication information. If this authentication is correct, the flow continues.
* **Apinizer** makes a request to **Backend API**.
* **Backend API** responds to **Apinizer**.
* **Apinizer** responds to **API Client**.

<img src="https://mintcdn.com/apinizer/onnph0cZV1IIZ7ZM/images/tutorials/ldap1.png?fit=max&auto=format&n=onnph0cZV1IIZ7ZM&q=85&s=89209186f4bde322748286e0cbad9b90" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap1.png" />

## Creating API Proxy

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo2.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=052195ac9313eff2da0121245624677f" alt="Scenario Diagram" width="200" data-path="images/tutorials/senaryo2.png" />

Access to the REST API named Swagger Petstore can be provided from [https://petstore.swagger.io/](https://petstore.swagger.io/).

Click the **API Proxies** option under the **Development** menu.

<Info>
  Since no **proxy** definition has been made before on the opened page, the text **No records found!** appears.
</Info>

Click the **Create** button in the top right corner and start creating a new **proxy**.

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo3.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=938b0de54e7641fce65b865f3f5182b0" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo3.png" />

In this section, it is necessary to select what type the **API Proxy** to be created is.

Since the type of API to be used in this scenario will be **Swagger 2.X**, this type is selected.

Click on the **Enter URL** expression to switch to the screen where the address of the API to be used will be entered.

<img src="https://mintcdn.com/apinizer/ocsi_kVjLluGlu4Z/images/tutorials/swagger.png?fit=max&auto=format&n=ocsi_kVjLluGlu4Z&q=85&s=13223791b611fc908487605c87b11809" alt="Senaryo Diyagramı" width="800" data-path="images/tutorials/swagger.png" />

Enter the **address to be accessed** in the URL section and click the **Parse** button.

<img src="https://mintcdn.com/apinizer/yvmWFcjBSxooF86u/images/tutorials/senaryo5.png?fit=max&auto=format&n=yvmWFcjBSxooF86u&q=85&s=ab4f310e6a80807e54f36f0c72c39e4e" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo5.png" />

After the Parse operation is performed, settings for the API Proxy can be made.

* The **Usage** field specifies who will use the created API Proxy. Options such as **publisher, consumer, publisher and consumer** are available here.
* The **Sharing Type** field specifies the sharing type of the created API Proxy. Options such as **external, internal, external and internal** are available here.
* One or both of the two API addresses under the **Addresses** tab can be selected. If both addresses are selected, Apinizer will perform the **Load Balance** operation itself.
* **Relative Path** is the address where the created API Proxy will be opened for access.
* The **Category List** field also allows categorization of the created API Proxy.

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo6.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=511fa694bec2af3fdd31ccc6bb17115f" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo6.png" />

After these settings are made, the API Proxy is saved.

After the save operation, click the **Develop** tab on the opened page.

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo7.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=423589a8890368635457719c9d59acec" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo7.png" />

<Info>
  Policies to be added with the **All** expression above these endpoints can be applied to **all endpoints**.
</Info>

The created API proxy is deployed. For this, click the **Deploy** button in the middle section above.

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo8.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=3338ba7df1da3c1536385471851b0fff" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo8.png" />

## Establishing LDAP/Active Directory Connection

Click the **LDAP/Active Directory** menu under the **Connection Management** menu.

<Info>
  Since no **LDAP/Active Directory** definition has been made before, the text **There is no LDAP/Active Directory** appears on this page.
</Info>

Click the **Create** button in the top right corner to create the **LDAP/Active Directory** connection.

<img src="https://mintcdn.com/apinizer/onnph0cZV1IIZ7ZM/images/tutorials/ldap2.png?fit=max&auto=format&n=onnph0cZV1IIZ7ZM&q=85&s=d396d48e14543168f4bd09d4188abce8" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap2.png" />

The fields on this screen:

* The **Name** field expresses the name of the connection to be created.
* The **Server Address** field writes the address of the **LDAP/Active Directory** server to be connected to.
* A description can be added to the created connection with the **Description** expression.
* The **Certificate Status** field selects or creates a new certificate required for LDAP connection.
* The **Username** field enters the username information to be used during connection, and the **Password** field enters the password to be used during connection.
* The **Base DN** field also specifies the base dn address of the LDAP to be connected to.

<img src="https://mintcdn.com/apinizer/onnph0cZV1IIZ7ZM/images/tutorials/ldap3.png?fit=max&auto=format&n=onnph0cZV1IIZ7ZM&q=85&s=96171311dcba5af825d83b117081edf5" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap3.png" />

Click the **Test Connection** button to perform the test, and click the **Save and Deploy** button to save the operations.

<img src="https://mintcdn.com/apinizer/onnph0cZV1IIZ7ZM/images/tutorials/ldap4.png?fit=max&auto=format&n=onnph0cZV1IIZ7ZM&q=85&s=f28007294160494e49d84a435aaee199" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap4.png" />

After the registration operation is completed, the created connection is displayed as in the image below.

<img src="https://mintcdn.com/apinizer/dOu0rEEHFhAKVsXF/images/tutorials/ldap5.png?fit=max&auto=format&n=dOu0rEEHFhAKVsXF&q=85&s=5dd3aed71663451d58b106c9923e689c" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap5.png" />

## Creating Authentication Policy

Go to the page where API proxies are listed and select the proxy named **Swagger Petstore** from here.

Go to the **Develop** tab and click the **Add Policy** button.

On the opened page, the **Plain-Text Authentication** policy is selected.

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo16.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=367541a5209beddc52b5a66748f67fba" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo16.png" />

The fields on this screen:

* The value to be selected in the **Identity/Role/Group Service** field is the **LDAP** value. Because authentication control will be performed by the structure in **LDAP/Active Directory**.
* When the LDAP value is selected, the previously created LDAP connection must be selected.
* The **Variable for username** and **variable for password** expressions also select which variable the username and password information will be retrieved with. In this scenario, these values will be retrieved from **header**.

<Warning>
  If the **Clear Authentication Information** option is selected, authentication information in the incoming message is deleted. Activating this setting is always recommended unless there is a special situation.
</Warning>

* The **Add Client Info To Header** option specifies whether client information will be present in the Header going to the backend API.
* If this option becomes active, another parameter named **Authenticated User Header Name** appears.
* The **X-Authenticated-UserId** expression here specifies the header name with which the client information going to the backend API will go.

<img src="https://mintcdn.com/apinizer/dOu0rEEHFhAKVsXF/images/tutorials/ldap6.png?fit=max&auto=format&n=dOu0rEEHFhAKVsXF&q=85&s=9339e886ff84bdaf8333f1439dfb6438" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap6.png" />

The changes made are saved by clicking the **Save** button in the top right corner.

<Info>
  The relevant icon is seen when the policy is registered.
</Info>

For the operation to be valid, the proxy must be **Redeployed**. Now the test operation of the methods in the proxy can be performed.

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo18.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=c4ae1f9417beee2244f0043a329af45b" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo18.png" />

## Testing the API Proxy

After selecting the **"/pet/{petId}"** endpoint, click the **Test Endpoint** button.

<img src="https://mintcdn.com/apinizer/VUbwu9iu7Snx108F/images/tutorials/senaryo19.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=0fc2801a24872962da9cfd6b67800561" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo19.png" />

Enter the desired **petId** value as **"2"** in the URL, and when the **Send** button is pressed, it is seen that the returned response is an error message.

<img src="https://mintcdn.com/apinizer/dOu0rEEHFhAKVsXF/images/tutorials/ldap7.png?fit=max&auto=format&n=dOu0rEEHFhAKVsXF&q=85&s=ebcb2ec44b6678a71c28c8763f556f81" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap7.png" />

<Warning>
  It is seen that this error is related to the applied **Plain-Text Authentication**. Because no **authentication** information has been placed in the **header** in any way.
</Warning>

Enter **username** and **password** expressions in the header and repeat the test.

Enter the values **username = user.9** and **password = Apinizer.1** in the **headers** to be sent to the **Backend API**.

When the **Send** button is clicked, a successful response is received.

<img src="https://mintcdn.com/apinizer/dOu0rEEHFhAKVsXF/images/tutorials/ldap8.png?fit=max&auto=format&n=dOu0rEEHFhAKVsXF&q=85&s=58fadb040c8714cb9fecddffd227cfe6" alt="Scenario Diagram" width="800" data-path="images/tutorials/ldap8.png" />
