| Line 55: | Line 55: | ||
This is how, concept-proof, KAuth works. However, please note that in your implementation you will have to deal with the pre-authorization phase only, since everything else is handled internally. | This is how, concept-proof, KAuth works. However, please note that in your implementation you will have to deal with the pre-authorization phase only, since everything else is handled internally. | ||
| + | |||
| + | == Creating Actions with KAuth == | ||
| + | To increase the level of security, authorization systems require to register the actions together with the application installation, so that the authorized actions are all known to the system administrator. This means that if you're using KAuth you probably want to register some new actions in the system. | ||
| + | |||
| + | This is done by creating a ''.actions'' file, which is a standard INI files containing a set of new actions. This file is translatable, and if you're developing your project in KDE SVN, scripty will take care of updating it. The file has the following format: | ||
| + | |||
| + | [org.kde.auth.example.action] | ||
| + | Name=Example action | ||
| + | Description=The system is attempting to perform the example action | ||
| + | Policy=auth_admin | ||
| + | Persistence=session | ||
| + | |||
| + | The fields are defined as follows: | ||
| + | |||
| + | *'''Title''': The action identifier | ||
| + | *'''Name''': A human readable action name | ||
| + | *'''Description''': This message will eventually be displayed to the user during the authentication phase, if any. | ||
| + | *'''Policy''': The default policy for this action. It can be one of the following values: | ||
| + | **''yes'': the action should be allowed without requesting authentication | ||
| + | **''no'': the action should be always denied, without requesting authentication | ||
| + | **''auth_self'': the action will be authorized if the user will authenticate as himself | ||
| + | **'auth_admin'': the action will be authorized if the user will authenticate as a system administrator | ||
| + | *'''Persistence''': this field is optional and takes effect only if the authorization system supports it and '''Policy''' is either ''auth_admin'' or ''auth_self''. It defines the persistence of the explicit authorization granted by the user through authentication. It can be one of the following values: | ||
| + | **''session'': the authorization persists until the user logs out | ||
| + | **''always'': the authorization will persist indefinitely | ||
| + | |||
| + | Once you defined the actions in your file (you can define an unlimited number of actions in an .actions file, however you can define only actions belonging to a certain namespace, for example org.kde.auth.example.*), KAuth provides a CMake macro to register the actions in the system. From your CMakeLists.txt, supposing your file is named org.kde.auth.example.actions, you would do: | ||
| + | |||
| + | kde4_install_auth_actions(org.kde.auth.example org.kde.auth.example.actions) | ||
| + | |||
| + | This macro has the following syntax: | ||
| + | |||
| + | kde4_install_auth_actions(<namespace_id> <actions definition file>) | ||
| + | |||
| + | Where namespace_id is the namespace where you defined your actions, in this case org.kde.auth.example. | ||
Contents |
Languages: عربي | Asturianu | Català | Česky | Kaszëbsczi | Dansk | Deutsch | English | Esperanto | Español | Eesti | فارسی | Suomi | Français | Galego | Italiano | 日本語 | 한국어 | Norwegian | Polski | Português Brasileiro | Română | Русский | Svenska | Slovenčina | Slovenščina | српски | Türkçe | Tiếng Việt | Українська | 简体中文 | 繁體中文
| Tutorial Series | KAuth Tutorial |
| Previous | |
| What's Next | Using the caller-helper model to perform actions as root |
| Further Reading | None |
KAuth (part of kdelibs/kdecore) is an authentication framework for KDE. Just like any other components in the KDE Development Platform, it is a wrapper around lower-level tools. If you're planning to use KAuth, however, you won't have to care about what authentication system is the system you're targeting using: KAuth will take care of that on its own.
In addition, KAuth is also able to perform privilege elevation on restricted portions of code (helpers), giving the developer an efficient and easy to use pipe to communicate with them, and making them secure throughout authorization.
There are a few concepts to understand when using KAuth. Much of those are carried from underlying APIs such as polkit, so if you are familiar with one of them you might as well skip this section.
Supposing that you want to use KAuth to perform a privileged operation and the action you are considering requires the user to authenticate (which is the most common use case of KAuth), the break down of phases would be:
This is how, concept-proof, KAuth works. However, please note that in your implementation you will have to deal with the pre-authorization phase only, since everything else is handled internally.
To increase the level of security, authorization systems require to register the actions together with the application installation, so that the authorized actions are all known to the system administrator. This means that if you're using KAuth you probably want to register some new actions in the system.
This is done by creating a .actions file, which is a standard INI files containing a set of new actions. This file is translatable, and if you're developing your project in KDE SVN, scripty will take care of updating it. The file has the following format:
[org.kde.auth.example.action] Name=Example action Description=The system is attempting to perform the example action Policy=auth_admin Persistence=session
The fields are defined as follows:
Once you defined the actions in your file (you can define an unlimited number of actions in an .actions file, however you can define only actions belonging to a certain namespace, for example org.kde.auth.example.*), KAuth provides a CMake macro to register the actions in the system. From your CMakeLists.txt, supposing your file is named org.kde.auth.example.actions, you would do:
kde4_install_auth_actions(org.kde.auth.example org.kde.auth.example.actions)
This macro has the following syntax:
kde4_install_auth_actions(<namespace_id> <actions definition file>)
Where namespace_id is the namespace where you defined your actions, in this case org.kde.auth.example.