Skip to content

Instantly share code, notes, and snippets.

@atomlab
Last active April 10, 2024 14:45
Show Gist options
  • Save atomlab/376901845c3d474d1e60e6b7a3affaae to your computer and use it in GitHub Desktop.
Save atomlab/376901845c3d474d1e60e6b7a3affaae to your computer and use it in GitHub Desktop.
Guacamole REST API Examples

Get token

curl -X POST -d 'username=MYUSERNAME&password=MYPASSWORD' http://localhost:8080/guacamole/api/tokens

output

{
  "authToken": "C90FE11682EE3A8CCA339F1135FF02D0A97CDDDE440A970B559D005517BE6EA8",
  "username": "guacadmin",
  "dataSource": "postgresql",
  "availableDataSources": [
    "postgresql",
    "postgresql-shared"
  ]
}

Encode client url string

  1. Get connections list
curl 'http://localhost:8080/guacamole/api/session/data/postgresql/connections?token=<TOKEN>'| jq

output

{
  "1": {
    "name": "win",
    "identifier": "1",
    "parentIdentifier": "ROOT",
    "protocol": "rdp",
    "attributes": {
      "guacd-encryption": null,
      "failover-only": null,
      "weight": null,
      "max-connections": null,
      "guacd-hostname": null,
      "guacd-port": null,
      "max-connections-per-user": null
    },
    "activeConnections": 0,
    "lastActive": 1591774964770
  },
  "2": {
    "name": "win1",
    "identifier": "2",
    "parentIdentifier": "ROOT",
    "protocol": "rdp",
    "attributes": {
      "guacd-encryption": null,
      "failover-only": null,
      "weight": null,
      "max-connections": null,
      "guacd-hostname": null,
      "guacd-port": null,
      "max-connections-per-user": null
    },
    "activeConnections": 1,
    "lastActive": 1591774407688
  }
}

Notes (link):

The necessary information is indeed there - you just need to know how to generate the URL. The base64 bit after ".../guacamole/client/" in the URL of a connection is built from the following information:

  1. The connection identifier (in MySQL / PostgreSQL, this will be the connection ID)
  2. The type ("c" for connections and "g" for balancing groups)
  3. The identifier of the auth provider storing the connection data (usually "postgresql", "mysql", or "ldap" - in your case the correct value would be "mysql")

Each of these components separated from the other by a single NULL character (U+0000), with the resulting string encoded with base64.

  1. Encode string
printf '2\0c\0postgresql' | base64

output

MgBjAHBvc3RncmVzcWw=
  1. URL
https://localhost:8080/guacamole/#/client/MgBjAHBvc3RncmVzcWw=
@frisedel
Copy link

oh thank you for this!!!

@iota-008
Copy link

iota-008 commented Mar 1, 2023

i don't want to pass the token in URL, instead in headers. but unable to open the URL in a new tab with headers...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment