# Sign-in for BCF clients

> How a BCF client signs in as a person, and how that differs from an integration's keys. SSO users cannot use a BCF client yet.

WhatsBuilt has two ways in for another system:

- **An integration** is your organisation's own system, such as an ERP or a data platform, with its own keys. It runs without a person and calls the REST API at `/v1`. See [Create an integration](/en/integrations/create-an-integration/) and [Get an access token](/en/integrations/get-an-access-token/).
- **A BCF client** signs in as a WhatsBuilt **user**, with a signed token from WhatsBuilt's sign-in service, and calls the BCF 3.0 API. A call can do what that user may do, and nothing more. This page is about that sign-in.

:::caution[Limits of the BCF sign-in]
- **It is for a person.** An unattended system should use [an integration](/en/integrations/create-an-integration/) instead.
- **SSO users cannot use a BCF client.** The BCF sign-in accepts WhatsBuilt passwords only. If your organisation signs in with SSO, its users cannot complete it.
- **No named desktop client has been verified.** The flow below is what the code offers. It has not been confirmed end to end with a specific BCF client.
:::

## Signing in a BCF client

`GET /foundation/1.1/auth` needs no token and returns the sign-in details:

```json
{
  "oauth2_auth_url": "https://auth.whatsbuilt.fi/oauth2/authorize",
  "oauth2_token_url": "https://auth.whatsbuilt.fi/oauth2/token",
  "oauth2_dynamic_client_reg_url": "",
  "http_basic_supported": false,
  "supported_oauth2_flows": ["authorization_code_grant"],
  "pkce_required": true,
  "code_challenge_method": "S256",
  "client_id": "<the WhatsBuilt BCF client>"
}
```

| Setting | Value |
|:--------|:------|
| Flow | Authorization code with PKCE (`S256`). No other flow |
| Client | Public: no client secret. Use the `client_id` above |
| Scopes | `openid`, `email`, `profile` |
| Redirect URIs | Exactly one of `http://localhost/auth/callback`, `http://localhost:3000/auth/callback`, `http://localhost:8080/auth/callback`, `http://localhost:9090/auth/callback`, `http://localhost:12345/auth/callback` |
| Identity provider | WhatsBuilt passwords only |
| ID and access token lifetime | 1 hour |
| Refresh token lifetime | 7 days |
| Dynamic client registration, HTTP basic | Not supported |

## Which token to send

Send the **access token** (`access_token` in the token response) as `Authorization: Bearer <token>`, as an OAuth client does by default. It must come from the BCF client above: an access token from any other client is refused. An ID token from the same client also works.

A token from the BCF client, access or ID, works only on `/bcf/3.0/*` and `/foundation/*`. The rest of the API refuses it with `403 TOKEN_CLIENT_NOT_ALLOWED`.

An access token holds no email, so the API looks the user up in the sign-in service and keeps the result for up to five minutes. The user behind that email must already exist in WhatsBuilt. A deleted or disabled user is refused once the kept result expires.

## Errors

| Status | Code | Meaning |
|:-------|:-----|:--------|
| `401` | None | The gateway refused a missing, expired or foreign token |
| `401` | `TOKEN_INVALID` | The token passed the gateway but the API does not accept it: for example an access token from another client, or a user who is deleted, disabled or not in WhatsBuilt |
| `403` | `TOKEN_CLIENT_NOT_ALLOWED` | A token from the BCF client was sent outside `/bcf/3.0/*` and `/foundation/*` |
| `403` | `INSUFFICIENT_PROJECT_ROLE` | The user's project role is too low |
| `503` | `COGNITO_LOOKUP_UNAVAILABLE` | The user lookup is temporarily unavailable. Retry after the `Retry-After` header, 5 seconds. The sign-in stays valid, so do not sign the user out |
| `503` | `COGNITO_KEYS_UNAVAILABLE` | The sign-in cannot be checked right now. Try again shortly, after the `Retry-After` header, 5 seconds. The sign-in stays valid, so do not sign the user out |

## What this means for a server integration

A system that runs without a person, such as an ERP or production planning, uses [an integration](/en/integrations/create-an-integration/) and the REST API, not the BCF sign-in. An integration's token is refused on the BCF API, and a BCF token is refused on `/v1`.

## See also

- [BCF 3.0 API and OpenCDE discovery](/en/integrations/bcf-api/)
- [API reference](/en/api-reference/)
