|
| 1 | +name = "Quickshell.Services.Polkit" |
| 2 | +description = "Polkit API" |
| 3 | +headers = [qml.hpp] |
| 4 | +----- |
| 5 | + |
| 6 | +## Purpose of a Polkit Agent |
| 7 | + |
| 8 | +PolKit is a system for privileged applications to query if a user is permitted to execute an action. |
| 9 | +You have probably seen it in the form of a "Please enter your password to continue with X" dialog box before. |
| 10 | +This dialog box is presented by your *PolKit agent*, it is a process running as your user that accepts authentication requests from the *daemon* and presents them to you to accept or deny. |
| 11 | + |
| 12 | +This service enables writing a PolKit agent in Quickshell. |
| 13 | + |
| 14 | +## Implementing a Polkit Agent |
| 15 | + |
| 16 | +The backend logic of communicating with the daemon is handled by the @@PolkitAgent object. |
| 17 | +It exposes incoming requests as properties and provides appropriate signals. |
| 18 | + |
| 19 | +### Flow of an authentication request |
| 20 | + |
| 21 | +Incoming authentication requests are queued in the order that they arrive. |
| 22 | +If none is queued, a request starts processing right away. |
| 23 | +Otherwise, it will wait until prior requests are done. |
| 24 | + |
| 25 | +A request starts by emitting the @@PolkitAgent.authenticationRequestStarted signal. |
| 26 | +At this point, information like the action to be performed and permitted users that can authenticate is available. |
| 27 | + |
| 28 | +An authentication *session* for the request is immediately started, which internally starts a PAM conversation that is likely to prompt for user input. |
| 29 | +* Additional prompts may be shared with the user by way of the @@PolkitAgent.subMessageChanged signal and the @@PolkitAgent.subMessage property. A common message might be 'Please input your password'. |
| 30 | +* An input request is forwarded via the @@PolkitAgent.inputRequestChanged signal and @@PolkitAgent.inputRequest property. Note that the request specifies whether the text box should show the typed input on screen or replace it with placeholders. |
| 31 | + |
| 32 | +User replies can be submitted via the @@PolkitAgent.submit method. |
| 33 | +A conversation can take multiple turns, for example if second factors are involved. |
| 34 | + |
| 35 | +If authentication fails, we automatically create a fresh session so the user can try again. |
| 36 | +The @@PolkitAgent.authenticationFailed signal is emitted in this case. |
| 37 | + |
| 38 | +If authentication is successful, you receive the @@PolkitAgent.authenticationSucceeeded signal. At this point, the dialog can be closed. |
| 39 | +If additional requests are queued, you will receive the @@PolkitAgent.authenticationRequestStarted signal again. |
| 40 | + |
| 41 | +#### Cancelled requests |
| 42 | + |
| 43 | +Requests may either be canceled by the user or the PolKit daemon. |
| 44 | +In this case, we clean up any state and proceed to the next request, if any. |
| 45 | + |
| 46 | +If the request was cancelled by the daemon and not the user, you also receive the @@PolkitAgent.authenticationRequestCancelled signal. |
| 47 | + |
| 48 | +## Limitations |
| 49 | + |
| 50 | +- If multiple authentication requests are queued, we cannot determine which one is canceled (if one is canceled) |
0 commit comments