> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs-unsw-v6.advance-uac.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs-unsw-v6.advance-uac.com/_mcp/server.

# Get access token

POST https://protocol/openid-connect/token
Content-Type: application/x-www-form-urlencoded

Obtains a Keycloak OAuth 2.0 access token using the **Client Credentials** grant type. The returned token is automatically saved to the `bearerToken` environment variable by the post-response script, making it available for subsequent authenticated requests.

## Request

**Method:** `POST`  
**URL:** `{{KEYCLOAK_URL}}/protocol/openid-connect/token`

### Body Parameters (URL-encoded)

| Parameter | Value | Description |
|---|---|---|
| `grant_type` | `client_credentials` | OAuth 2.0 grant type for machine-to-machine authentication |
| `client_id` | `{{KEYCLOAK_CLIENT_ID}}` | The client identifier registered in Keycloak |
| `client_secret` | `{{KEYCLOAK_CLIENT_SECRET}}` | The client secret associated with the client ID |

## Response

On success, Keycloak returns a JSON object containing:

- `access_token` — The JWT bearer token to use in the `Authorization` header of subsequent API requests
- `expires_in` — Token lifetime in seconds
- `token_type` — Will be `Bearer`

## Post-response Script

After a successful response, the post-response script automatically:
1. Extracts the `access_token` from the response body
2. Saves it to the `bearerToken` environment variable
3. Logs the token expiry time to the console

## Environment Variables Required

| Variable | Description |
|---|---|
| `KEYCLOAK_URL` | Base URL of the Keycloak server (e.g. `https://keycloak-dev.uac.edu.au:8443/realms/advance_reload`) |
| `KEYCLOAK_CLIENT_ID` | Client ID registered in Keycloak |
| `KEYCLOAK_CLIENT_SECRET` | Client secret for the registered client |

Reference: https://docs-unsw-v6.advance-uac.com/unsw-advance-institution-api/get-access-token

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: collection
  version: 1.0.0
paths:
  /protocol/openid-connect/token:
    post:
      operationId: Get access token
      summary: Get access token
      description: >-
        Obtains a Keycloak OAuth 2.0 access token using the **Client
        Credentials** grant type. The returned token is automatically saved to
        the `bearerToken` environment variable by the post-response script,
        making it available for subsequent authenticated requests.


        ## Request


        **Method:** `POST`  

        **URL:** `{{KEYCLOAK_URL}}/protocol/openid-connect/token`


        ### Body Parameters (URL-encoded)


        | Parameter | Value | Description |

        |---|---|---|

        | `grant_type` | `client_credentials` | OAuth 2.0 grant type for
        machine-to-machine authentication |

        | `client_id` | `{{KEYCLOAK_CLIENT_ID}}` | The client identifier
        registered in Keycloak |

        | `client_secret` | `{{KEYCLOAK_CLIENT_SECRET}}` | The client secret
        associated with the client ID |


        ## Response


        On success, Keycloak returns a JSON object containing:


        - `access_token` — The JWT bearer token to use in the `Authorization`
        header of subsequent API requests

        - `expires_in` — Token lifetime in seconds

        - `token_type` — Will be `Bearer`


        ## Post-response Script


        After a successful response, the post-response script automatically:

        1. Extracts the `access_token` from the response body

        2. Saves it to the `bearerToken` environment variable

        3. Logs the token expiry time to the console


        ## Environment Variables Required


        | Variable | Description |

        |---|---|

        | `KEYCLOAK_URL` | Base URL of the Keycloak server (e.g.
        `https://keycloak-dev.uac.edu.au:8443/realms/advance_reload`) |

        | `KEYCLOAK_CLIENT_ID` | Client ID registered in Keycloak |

        | `KEYCLOAK_CLIENT_SECRET` | Client secret for the registered client |
      tags:
        - ''
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Get access token_Response_200'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                grant_type:
                  type: string
                client_id:
                  type: string
                client_secret:
                  type: string
              required:
                - grant_type
                - client_id
                - client_secret
servers:
  - url: https:/
    description: https://{baseurl}
components:
  schemas:
    Get access token_Response_200:
      type: object
      properties:
        access_token:
          type: string
        expires_in:
          type: integer
        refresh_expires_in:
          type: integer
        token_type:
          type: string
        not-before-policy:
          type: integer
        scope:
          type: string
      required:
        - access_token
        - expires_in
        - refresh_expires_in
        - token_type
        - not-before-policy
        - scope
      title: Get access token_Response_200
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

```

## Examples



**Request**

```json
{
  "grant_type": "string",
  "client_id": "string",
  "client_secret": "string"
}
```

**Response**

```json
{
  "access_token": "encoded_access_token",
  "expires_in": 1800,
  "refresh_expires_in": 0,
  "token_type": "Bearer",
  "not-before-policy": 0,
  "scope": "email profile"
}
```

**SDK Code**

```python Get access token_example
import requests

url = "https://https/protocol/openid-connect/token"

payload = ""
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/x-www-form-urlencoded"
}

response = requests.post(url, data=payload, headers=headers)

print(response.json())
```

```javascript Get access token_example
const url = 'https://https/protocol/openid-connect/token';
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  body: new URLSearchParams('')
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go Get access token_example
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://https/protocol/openid-connect/token"

	req, _ := http.NewRequest("POST", url, nil)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby Get access token_example
require 'uri'
require 'net/http'

url = URI("https://https/protocol/openid-connect/token")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/x-www-form-urlencoded'

response = http.request(request)
puts response.read_body
```

```java Get access token_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://https/protocol/openid-connect/token")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/x-www-form-urlencoded")
  .asString();
```

```php Get access token_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://https/protocol/openid-connect/token', [
  'form_params' => null,
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
]);

echo $response->getBody();
```

```csharp Get access token_example
using RestSharp;

var client = new RestClient("https://https/protocol/openid-connect/token");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
IRestResponse response = client.Execute(request);
```

```swift Get access token_example
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/x-www-form-urlencoded"
]

let request = NSMutableURLRequest(url: NSURL(string: "https://https/protocol/openid-connect/token")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```