# Authentication

``` http
POST https://login.microsoftonline.com/[tenantID]/oauth2/v2.0/token
```

[tenantID] is the Entra ID (fka Azure Active Directory) tenant ID where your application is registered.
Payload is x-www-form-urlencoded with these key-values:

- `grant_type = client_credentials`
- `client_id` = [application/client ID from the app registration in Entra ID]
- `client_secret` = [secret from the app registration]
- `scope` = [depends on which UtilityCloud environment you want to use]
  - for staging use: `http://api-stag.utilitycloud.app/.default`
  - for production use: `http://api.utilitycloud.app/.default`

Example in curl ([curl.se](https://curl.se))

``` bash
curl --location 'https://login.microsoftonline.com/YOUR_TENANT_ID/oauth2/v2.0/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=SCOPE' \
--data-urlencode 'client_id=YOUR_CLIENT_ID' \
--data-urlencode 'client_secret=YOUR_SECRET'
```

Response

``` json
{
    "token_type": "Bearer",
    "access_token": "eyJ0 ... Cv6OA"
}
```

Use the acquired `access_token` in subsequent requests to UC's APIs.

For å quick test you can try this:

``` bash
curl --location 'https://api-stag.utilitycloud.app/cm/servicetypes/v2/servicetypes' \
--header 'Authorization: Bearer ACCESS_TOKEN_FROM_LOGIN_REQUEST'
```

