> ## 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 Basic (Base64) Authentication Policy to REST API via Security Manager Provider

> Explains how to apply Basic (Base64) Authentication policy to Swagger Petstore REST API via Security Manager provider. Includes all steps from credential creation to variable definition, adding policy to Base64 encryption and testing.

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

* **Security Manager** in **Apinizer** requests **Basic (Base64) type authentication** information from **API Client**. 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/VUbwu9iu7Snx108F/images/tutorials/senaryo1.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=aa3e5c64acf513f6af7595e8ce9c448c" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo1.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" />

## Creating Credentials

The information for the **Credential** to be added will be **username = apinizer**, **password = 123123aA**.

Go to the **Identity Management** menu.

Here, click the **Credentials** menu under the **Credential Management** menu.

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

Click the **Create** button in the top right corner on the opened screen.

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

Here, the required fields are filled with the previously specified information and the created **credential** is saved by clicking the **Save and Deploy** button.

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

The proxy that this **credential element** will provide access to must be selected. Hover over the created **credential** and click the **Edit** option from the menu on the side.

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

Click the **API Proxy ACL** tab from the opened screen, and click the button in this tab.

<img src="https://mintcdn.com/apinizer/bxDpmriTStVknLzL/images/tutorials/api-proxy-acl.png?fit=max&auto=format&n=bxDpmriTStVknLzL&q=85&s=4382f031671c9a1db129f0cbec08544f" alt="Scenario Diagram" width="800" data-path="images/tutorials/api-proxy-acl.png" />

On the opened page, **API Proxies** in the project currently being worked on are listed. The **proxy** named **Swagger Petstore** is selected.

Click the **Add** button to specify that the created **Credential** element will have access to this **proxy**.

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

Click the **Save and Deploy** button in the top right corner and save the operation.

<img src="https://mintcdn.com/apinizer/DnFDBUWIRDlha2Jf/images/tutorials/save.png?fit=max&auto=format&n=DnFDBUWIRDlha2Jf&q=85&s=8ba1e2ddbbe1b48baf9a833b3337b967" alt="Scenario Diagram" width="600" data-path="images/tutorials/save.png" />

## Variable Definition

The definition of the variable to be used in the policy must be made.

Click the **Add** button.

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

* Enter the name of the variable to be created in the **Name** input field.
* The **Type** field specifies the type of variable to be used.
* The **Header Name** field expresses what name the variable to be used will be named in the **Header**.

The changes made are saved by clicking the **Save** button.

<img src="https://mintcdn.com/apinizer/DnFDBUWIRDlha2Jf/images/tutorials/new2.png?fit=max&auto=format&n=DnFDBUWIRDlha2Jf&q=85&s=2c76cd415a8383d789fe2427a38d4e13" alt="Scenario Diagram" width="600" data-path="images/tutorials/new2.png" />

## Adding Authentication Policy

The **Basic (Base64) Authentication** policy can now be added.

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

Then go to the **Develop** tab and click the **Add Policy** button.

On the opened page, the **Basic Authentication** policy is selected.

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

The fields on this screen:

* The value to be selected in the **Identity/Role/Group Service** field is the **Security Manager** value. Because credentials control will be performed by **Security Manager**.
* In the **Variable for authorization** field, since the **authentication** type used is **Basic** (**Base64**) and in this **authentication** type the **username**-**password** information used is encrypted, this expression is used. In this scenario, this value 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/rZqg5lxKC5oWIa_w/images/tutorials/basic.png?fit=max&auto=format&n=rZqg5lxKC5oWIa_w&q=85&s=a0476b25e657ff355660f72baf73ecf1" alt="Scenario Diagram" width="800" data-path="images/tutorials/basic.png" />

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

For the operation to be valid, the proxy must be **Deployed**.

<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/VUbwu9iu7Snx108F/images/tutorials/senaryo20.png?fit=max&auto=format&n=VUbwu9iu7Snx108F&q=85&s=f1447dd29f06ed937156c80284a4a03b" alt="Scenario Diagram" width="800" data-path="images/tutorials/senaryo20.png" />

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

Since **Basic (Base64) Authentication** is used in this proxy, the **username** and **password** information must be **encrypted** in this direction.

## Performing Base64 Type Encryption

Select the **Toolbox** menu under the **Test** menu. Here, there is a tool that can perform **encode** and **decode** in **Base64** encryption format. This tool is selected.

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

Write the expressions you want to encrypt in the **decoded data** field, and the encrypted data is obtained in the **encoded data** field.

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

The **username** and **password** information, which is the **Encoded** version, is obtained from here and go back to the page where **proxies** are listed.

Select the proxy named **Swagger Petstore**.

Switch to the **Develop** tab, select the **"/pet/{petId}"** endpoint from the endpoints listed here, and click **Test Endpoint**.

Enter the desired **petId** value as **"2"** again in the URL.

Enter the **Authorization** expression in the **Headers** and enter the **encoded username and password** information in **Base64** format as its value.

Click the **Send** button to perform the data retrieval operation according to the specified **id**.

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