Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

To Set Up Basic Authentication (Design Center)

This procedure demonstrates how to set up basic authentication. An HTTP user agent uses basic authentication to provide a user name and password when making a request. For example, you send a request to the Github API for user information. The Github API accepts requests for user information on port 443 to https://api.github.com/user.

  1. In a new project, set up an HTTP Listener operation to start an app from a browser.

  2. Click + to add another component to the flow, and select HTTP Request.

  3. In HTTP Request, click Edit. Set up the request configuration:

    • Accept the default configuration name HTTP Request.

    • In Protocol, select HTTPS.

    • Set the host to api.github.com.

    • Set the port to 443.

    • Accept the other defaults. Do not set the Base Path in URL Configuration.

  4. Click Authentication and do the following things:

    • Select Basic Authentication.

    • Check Preemptive

    • In Username, type your Github user name.

    • In Password, type either your Github password or a personal access token.

    • Save.

  5. In Path or URL, type /user and in Method, select GET.

  6. Click Deploy, and the execute the flow:

    • Click Copy Link.

    • Paste the link in a browser or client, and type /trigger at the end.

      The github information appears in the browser.

      {"login":"max","id":16xxx11,"avatar_url":"https://avatars0.githubusercontent.com/u/16xxx11?v=3","gravatar_id":"","url":"https://api.github.com/users/max
      ...
      ,"collaborators":0,"private_repos":0}}
  7. In HTTP Request > Output, in Show, select Payload.

    The github information also appears correctly formatted.

    {
      "login": "max",
      "id": 16xxx11,
      "avatar_url": "https://avatars0.githubusercontent.com/u/16125343?v=3",
      "gravatar_id": "",
    ...
        "collaborators": 0,
        "private_repos": 0
      }
    }

In this topic: