guacamole-connection-fetch
v1.0.2
Published
Fetch-based Guacamole connection client for browser/edge runtimes.
Maintainers
Readme
guacamole-connection-fetch
Isomorphic Guacamole token generation and connection helper for encrypted JSON authentication, written in vanilla JS. For use in Node.js, Cloudflare Workers, web browsers, or serverless environments
Requires the Fetch API (e.g. fetch(request)) to be available
Usage
import { GuacamoleUserConnection } from "guacamole-connection-fetch"
/**
makes request to '/api/tokens' via fetch()
*/
async function interceptApiTokensRequest (request) {
// properly formed, minified JSON string as described in https://github.com/ridvanaltun/guacamole-rest-api-documentation/blob/master/docs/AUTHENTICATION.md#post-apitokens
const conns = {"Ubuntu origin 10.91.0.101":{"protocol":"ssh","parameters":{"dest-port":"22","hostname":"10.91.0.101","username":"UBUNTU_USERNAME","password":"UBUNTU_PASSWORD"}},"Win11 client 10.90.0.103":{"protocol":"rdp","parameters":{"ignore-cert":"true","enable-wallpaper":"true","security":"nla","username":"WINDOWS_USERNAME","password":"WINDOWS_PASSWORD","hostname":"10.90.0.103","dpi":"96","enable-font-smoothing":"true","enable-desktop-composition":"true","enable-menu-animations":"true","port":"3389"}}}
const res = await new GuacamoleUserConnection({
req: new Request("/api/tokens", request),
secretKey: GUAC_JSON_SECRET_KEY,
conns,
username: USER_EMAIL,
expires: 1990964469612,
headers: new Headers({
"Content-Type": "application/json",
// if using Cloudflare Access, pass these:
"cf-access-client-id": CF_ACCESS_SERVICE_TOKEN_CLIENT_ID,
"cf-access-client-secret": CF_ACCESS_SERVICE_TOKEN_CLIENT_SECRET,
...request.headers,
}),
}).retrieveToken();
return new Response(res.body, res);
}
interceptApiTokensRequest(request);
Installation
npm install guacamole-connection --save-dev
# or
pnpm add guacamole-connection
# or
yarn add guacamole-connection