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

# From Scratch

> Create a custom app by performing setup from scratch

To create a custom app from scratch, click on `+ Add App` in the **Custom Apps** section of Refold, choose `+ Create from Scratch` and specify **Name**, **Description** and **Slug** to identify the app within the Refold platform and click on `Create`.

<img height="200" src="https://mintcdn.com/cobalt-55/yYFE4rj1UK1LIP4D/images/Guides/Platform/custom-app.png?fit=max&auto=format&n=yYFE4rj1UK1LIP4D&q=85&s=2866b2e61010bf55c7b3502d23856397" alt="Custom App in the Apps list in Refold" data-path="images/Guides/Platform/custom-app.png" />

## Authentication Methods

Custom Apps support multiple authentication methods. To setup the Authorization for the Custom App, navigate to `Authorization` in the App and choose the desired method.

The methods of **Authorization** are:

<Accordion title="Key Based ">
  If the Custom App requires API Key based authentication, select `Key Based`. It requires users to set up an API for generating access tokens.

  <img height="200" src="https://mintcdn.com/cobalt-55/vPGojg1WCLHlMpWZ/images/Guides/Platform/key.png?fit=max&auto=format&n=vPGojg1WCLHlMpWZ&q=85&s=6805e2b9da6dec492ae381102085c801" alt="Key-based authorization" data-path="images/Guides/Platform/key.png" />

  Follow the steps below to setup your custom app:

  <Steps>
    <Step title="Select Key Auth type">
      Select either of **Basic Auth**, **Bearer Token** or **API Key** as the auth mechanism.
    </Step>

    <Step title="Configure User Input Fields">
      Add the input fields that will be visible to your users asking for the required API credentials and click on `Save`.
    </Step>

    <Step title="Map Auth fields">
      Once you have added the required user input fields, map those fields now to setup auth data.

      <img height="200" src="https://mintcdn.com/cobalt-55/vPGojg1WCLHlMpWZ/images/Guides/Platform/key-setup.png?fit=max&auto=format&n=vPGojg1WCLHlMpWZ&q=85&s=75fec73dceef2f629a2a18c8dbff83f9" alt="Key-based authorization setup" data-path="images/Guides/Platform/key-setup.png" />
    </Step>

    <Step title="Add Base URL">
      Provide the Base URL of the API endpoints for the custom app and the key code for Invalid API Credentials.
    </Step>

    <Step title="Setup Identifier and Validation">
      Optionally, you can also provide an endpoint which will be called to perform validation of the provided credentials.

      <Tip>
        Its recommended to provide a GET API endpoint to perform validation, so as to avoid modifying any data using the credentials.
      </Tip>

      <img height="200" src="https://mintcdn.com/cobalt-55/vPGojg1WCLHlMpWZ/images/Guides/Platform/key-valid.png?fit=max&auto=format&n=vPGojg1WCLHlMpWZ&q=85&s=5f4cad9cea2243021019ef9d3504d151" alt="Key-based auth validation" data-path="images/Guides/Platform/key-valid.png" />
    </Step>
  </Steps>

  <Check>
    Congratulations!

    You have successfully setup a Key based Custom Application in Refold.
  </Check>
</Accordion>

<Accordion title="OAuth 2.0 ">
  If you want to provide OAuth 2.0 type authorization, select `OAuth 2.0` in the methods.

  <img height="200" src="https://mintcdn.com/cobalt-55/vPGojg1WCLHlMpWZ/images/Guides/Platform/oauth_setup.png?fit=max&auto=format&n=vPGojg1WCLHlMpWZ&q=85&s=cd2b6a44d16de6e207a5bd790ac97eca" alt="OAuth 2.0 authorization" data-path="images/Guides/Platform/oauth_setup.png" />

  Follow the steps below to configure OAuth mechanism for your custom app:

  <Steps>
    <Step title="Provide OAuth Credentials">
      Add the **Client ID**, **Client Secret** and the **Scopes** of the developer OAuth 2.0 app that you have created.

      <Warning>
        Ensure that you add the provided `Callback URL` in your developer OAuth 2.0 app.
      </Warning>
    </Step>

    <Step title="Add Authorization and Token URL">
      Add the Authorization and Token URL required for OAuth authentication in the provided fields, select `Client Authentication` type and `Save`.

      <Info>
        You can find both the URLs from the Authentication documentation of the custom app that you are setting up.
      </Info>
    </Step>

    <Step title="Setup Refresh Mechanism and API Base URL">
      In the `API Setup` section, provide the **Base URL** for the APIs and appropriate code i.e. **Expired Access Token Codes** which is received on token expiry for the Refresh mechanism to work.

      <img height="200" src="https://mintcdn.com/cobalt-55/vPGojg1WCLHlMpWZ/images/Guides/Platform/oauth_refresh.png?fit=max&auto=format&n=vPGojg1WCLHlMpWZ&q=85&s=8eb7594fbf6fe4cd928c33545115020b" alt="OAuth 2.0 Refresh mechanism" data-path="images/Guides/Platform/oauth_refresh.png" />
    </Step>

    <Step title="Extract Access Token & Refresh Token">
      In the `Auth Tokens Data` section, you will provide the mapping using which the tokens can be extracted once received on callback on successful authorization.

      Usually an object is received after authorization which will be saved as `access_token_response` on Refold's end and you need to provide the key mapping of the required fields from the object.
    </Step>

    <Step title="Setup Identifier">
      Optionally, you can also provide an endpoint which will be called and used to set a field from the API response to use as an identifier for the user.

      <Tip>
        Its recommended to provide a GET API endpoint to perform validation, so as to avoid modifying any data using the credentials.
      </Tip>

      <img height="200" src="https://mintcdn.com/cobalt-55/vPGojg1WCLHlMpWZ/images/Guides/Platform/oauth_tokens.png?fit=max&auto=format&n=vPGojg1WCLHlMpWZ&q=85&s=cd36b360eeed734e2b187c0536621f13" alt="Setup an Identifier of your users" data-path="images/Guides/Platform/oauth_tokens.png" />
    </Step>
  </Steps>

  <Check>
    Congratulations!

    You have successfully setup a OAuth 2.0 Custom Application in Refold.
  </Check>
</Accordion>

<Accordion title="No Auth">
  Select this option if no authentication is required for accessing the custom app.
</Accordion>

## Custom Actions for App

Custom Apps support the addition of Actions of APIs.

#### Create Custom Action

Select `Custom Actions`, click on the `New Action` button and provide a **Name** and **Description**.

Add any required or optional **Fields** for the API and add the API under `API Call` section.

<Note>
  Provide the API by breaking it into 2 parts i.e. Base URL and the Endpoint.
</Note>

<img height="200" src="https://mintcdn.com/cobalt-55/yYFE4rj1UK1LIP4D/images/Guides/Platform/actions.png?fit=max&auto=format&n=yYFE4rj1UK1LIP4D&q=85&s=e21dacdfc053576c1f115d1b00f3bdcf" alt="Actions in the Custom App" data-path="images/Guides/Platform/actions.png" />

#### Enable Pagination for Custom Action

If the Action's API supports pagination, then you can add it to the custom action. Go to the **API Call** section and enable the `Pagination` toggle.

In the `Type` field, select the pagination type and provide the required fields and click on `Save API Call`.

<img height="200" src="https://mintcdn.com/cobalt-55/yYFE4rj1UK1LIP4D/images/Guides/Platform/action_pagination.png?fit=max&auto=format&n=yYFE4rj1UK1LIP4D&q=85&s=a53b0b9f66e62040ab93f26fd9d4c243" alt="Actions Pagination in the Custom App" data-path="images/Guides/Platform/action_pagination.png" />
