# Authentication

Every request to the JobLauncher API has to be authenticated. There are two ways to do it, and which one you use depends on how your integration is built.

## Which one do I use?

| Method | Use it when | What you get from eQuest |
| --- | --- | --- |
| **Basic auth** | Your integration posts jobs for one eQuest account, like an in-house HR team connecting its own system. | An API username and password for testing. Production credentials come from the customer (see below). |
| **OAuth 2.0** | Your integration posts jobs for many eQuest customers, like an ATS or HR platform that lets each of its customers connect their own eQuest account. Also used for one-off integrations where OAuth is required. | A client ID and client secret for testing and for production, plus setup documentation. |

Not sure? Email [api-support@equest.com](mailto:api-support@equest.com). Most ATS and HR platforms use OAuth 2.0.

## Where credentials come from

Testing and production credentials come from different places.

| Environment | Who provides them |
| --- | --- |
| **Testing** | eQuest. Email [api-support@equest.com](mailto:api-support@equest.com) and say which method you'll use. You get test credentials with a set of test boards and permissions already assigned. |
| **Production** | The customer. The customer's eQuest admin, or someone setting things up on their behalf like their implementation team, creates the eQuest posting account or accounts the integration will use. Those accounts decide which boards and inventory the integration can see. |

The customer's admin also sets up their job boards and board permissions in eQuest. Depending on how many boards and accounts they have, that can take anywhere from a few hours to a few days, so ask them to start early.

> Testing and production credentials are separate and don't work in each other's environment. A 401 error is often just the wrong set of credentials for the base URL you're calling.

## Basic auth

Send your API username and password in the `Authorization` header on every request, encoded the standard Basic auth way. Most HTTP tools do this for you.

```text
curl https://joblauncher.testing.equest.com/api/boards \
  -u 'USERNAME:PASSWORD' \
  -H 'Accept: application/json' \
  -H 'X-Accept-Version: 1.12.0'
```

That sends this header:

```text
Authorization: Basic VVNFUk5BTUU6UEFTU1dPUkQ=
```

## OAuth 2.0

### How setup works

eQuest sets up OAuth 2.0 for each integration, not for each customer.

| If you are... | Setup |
| --- | --- |
| An ATS or HR platform building one integration for all your customers | eQuest configures OAuth once for your platform. Every customer you connect after that uses the same configuration. You don't need a new setup for each customer. |
| A one-off integration that requires OAuth 2.0 | eQuest configures OAuth just for you, and the setup is specific to your integration. |

### Getting your OAuth credentials

1.  Email [api-support@equest.com](mailto:api-support@equest.com) and say you need OAuth 2.0 for the JobLauncher API.
2.  eQuest sets up the integration on our side.
3.  You get setup documentation plus a **client ID** and **client secret** for **testing**, and a separate client ID and client secret for **production**.
4.  Build and test against the testing environment first, using the test posting user eQuest gives you. Switch to the production client ID and secret when you go live.
5.  In production, each user signs in with an eQuest posting account the customer created for them.

### How it works

The JobLauncher API uses the standard OAuth 2.0 authorization code flow. Each of your users signs in with their own eQuest account once, and your app gets a token to post on their behalf.

| Item | Testing | Production |
| --- | --- | --- |
| Authorization URL | `https://auth.testing.equest.com/oauth/authorize` | `https://auth.equest.com/oauth/authorize` |
| Token URL | `https://auth.testing.equest.com/oauth/token` | `https://auth.equest.com/oauth/token` |
| Scope | `joblauncher.equest.com/jobs` |
| Token lifetime | 60 minutes. Use the refresh token to get a new one. |

For testing, eQuest also gives you a test posting user so you can sign in and try the flow yourself.

### Step 1: Send the user to eQuest to sign in

Redirect the user to the authorization URL with your client ID and the address to send them back to:

```text
https://auth.testing.equest.com/oauth/authorize?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=https://yourats.com/equest/callback
```

The user signs in with their eQuest username and password. eQuest then shows them what access your app is asking for, and they approve it.

### Step 2: Get the code

eQuest sends the user back to your `redirect_uri` with a one-time code on the end:

```text
https://yourats.com/equest/callback?code=AUTHORIZATION_CODE
```

### Step 3: Trade the code for a token

From your server, send the code to the token URL:

```text
curl -X POST https://auth.testing.equest.com/oauth/token \
  -d 'grant_type=authorization_code' \
  -d 'code=AUTHORIZATION_CODE' \
  -d 'redirect_uri=https://yourats.com/equest/callback' \
  -d 'client_id=YOUR_CLIENT_ID' \
  -d 'client_secret=YOUR_CLIENT_SECRET'
```

You get back an access token and a refresh token:

```text
{
  "access_token": "ebdd9302f01f4da56eacbfb93b6ef5f70dfa5ea7",
  "expires_in": 3600,
  "token_type": "Bearer",
  "scope": "joblauncher.equest.com/jobs",
  "refresh_token": "3aef28a87b26cf0b0aec0b0702ec3c122e5404cf"
}
```

Store both for that user.

### Step 4: Call the API with the token

```text
curl https://joblauncher.testing.equest.com/api/boards \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Accept: application/json' \
  -H 'X-Accept-Version: 1.12.0'
```

### Step 5: Refresh the token when it expires

Access tokens last 60 minutes. When one expires, use the refresh token to get a new one without sending the user back to sign in:

```text
curl -X POST https://auth.testing.equest.com/oauth/token \
  -d 'grant_type=refresh_token' \
  -d 'refresh_token=YOUR_REFRESH_TOKEN' \
  -d 'client_id=YOUR_CLIENT_ID' \
  -d 'client_secret=YOUR_CLIENT_SECRET'
```

The response has a new access token.

## Keeping credentials safe

-   Keep the client secret and API password on your server. Never put them in a browser, a mobile app, or a public code repository.
-   Always use HTTPS. Requests over plain HTTP are not supported.
-   If a secret or password may have leaked, email [api-support@equest.com](mailto:api-support@equest.com) right away to have it replaced.

## Common problems

| What you see | Likely cause |
| --- | --- |
| `401` on every call | Wrong credentials for the environment. Testing credentials only work on the testing base URL, and production only on production. |
| `401` after it was working | For OAuth, the access token expired. They last 60 minutes, so use the refresh token to get a new one. For Basic auth, the password may have been changed. |
| The sign-in page shows an error before the user signs in | The client ID or redirect address doesn't match what eQuest set up for your integration. Check your setup documentation. |
