There isn't currently any specific documentation on registering custom
field types, but there are some examples in the source that might be
instructive. You don't need to modify the guacamole-client source - there
is a system built-in intended for custom field types. You can do this
purely with an extension.

Take a look at the TOTP extension, which uses a fairly involved custom
field type for the enrollment process:

https://github.com/apache/guacamole-client/blob/master/extensions/guacamole-auth-totp/src/main/java/org/apache/guacamole/auth/totp/form/AuthenticationCodeField.java
(Java definition)

https://github.com/apache/guacamole-client/blob/master/extensions/guacamole-auth-totp/src/main/resources/config/totpConfig.js
(JavaScript registration of the type)

https://github.com/apache/guacamole-client/blob/master/extensions/guacamole-auth-totp/src/main/resources/totpModule.js
(JavaScript registration of the AngularJS module handling the custom field
registration)

The Java field will be automatically serialized into JSON, included in the
auth response, and then processed and passed to your custom field when
received by the browser.

The Duo extension also leverages custom fields for similar purposes.

- Mike

On Mon, Dec 5, 2022, 10:23 PM Joachim Lindenberg <guacam...@lindenberg.one>
wrote:

> Hello Mike,
>
> is there any documentation or example on how to add a custom field type? I
> assume this would require to clone or contribute to guacamole-client?
>
> Thanks,
> Joachim
>
>
>
> *Von:* Michael Jumper <mjum...@apache.org>
> *Gesendet:* Dienstag, 6. Dezember 2022 00:42
> *An:* user@guacamole.apache.org
> *Betreff:* Re: Additional field (select options) on login screen?
>
>
>
> On Mon, Dec 5, 2022 at 3:01 PM Joachim Lindenberg <
> guacam...@lindenberg.one> wrote:
>
> Hello Mike,
>
>
>
> I modified my code to show an addition filed using that exception, however
> the result is not exactly what I was looking for.
>
> With code like…
>
>
>
>    *static* *final* String *backupserver* = "backup-server-to-connect-to";
>
>     *private* *static* Field *BACKUPSERVER* = *null*;
>
>     *private* *static* CredentialsInfo *SERVER_USERNAME_PASSWORD* = *null*
> ;
>
> …
>
>       *if* (*BACKUPSERVER* == *null*) *BACKUPSERVER* = *new* EnumField(
> *backupserver*, *getBackupServerCollection*());
>
>       *if* (*SERVER_USERNAME_PASSWORD* == *null*)
> *SERVER_USERNAME_PASSWORD* =
>
>             *new* CredentialsInfo(Arrays.*asList*(
>
>                  *BACKUPSERVER*,
>
>                   CredentialsInfo.*USERNAME*,
>
>                   CredentialsInfo.*PASSWORD*
>
>               ));
>
>       *throw* *new* GuacamoleInsufficientCredentialsException ("server,
> user & password required", *SERVER_USERNAME_PASSWORD*);
>
>
>
> … I get a drop down with the content
> LOGIN.FIELD_OPTION_BACKUP_SERVER_TO_CONNECT_TO_BACKUP2_LINDENBERG_ONE in
> the UI.
>
> Looks like the client application takes my field name and values,
> concatenates them, and probably also tries to translate them, whereas I
> want to use the Values in EnumField as provided. How can I achieve that?
>
>
>
> You cannot do this with EnumField. All of the standard field types
> included with Guacamole that allow you to specify possible values will
> expect translation strings for each of those possible values. You would
> have to define your own custom field type if you cannot provide translation
> strings for the possible values ahead of time.
>
>
>
> Is there some other UI element more appropriate?
>
>
>
> Also while the exception provides an easy way to define fields, the
> Credentials type does not reflect that. I figured out I have to use
> something like
>
> credentials.getRequest().getParameter(*backupserver*))
>
> correct?
>
>
>
> Yes, convenience functions are provided only for username and password.
> You need to use the generic getParameter() for anything more specialized.
>
>
>
> - Mike
>
>
>

Reply via email to