| Line 60: | Line 60: | ||
== Creating Actions with KAuth == | == 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. | 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. | ||
| + | |||
| + | === Naming actions and namespaces === | ||
| + | Many authorization systems are quite strict about action naming, hence staying compatible with all of them is a tricky task. To ensure maximum compatibility with all of them, use, both in action namespaces and action names, '''only lowercase letters and numbers'''. Here comes a small example: | ||
| + | |||
| + | *''org.kde.auth.example.read'' '''OK''' | ||
| + | *''org.KDE.auth.example.read'' '''NOT OK''' | ||
| + | *''org.kde.auth.example-1.read'' '''NOT OK''' | ||
| + | *''org.kde.auth.example.readFile'' '''NOT OK''' | ||
| + | *''org.kde.auth.example.readfile'' '''OK''' | ||
| + | |||
| + | Please always keep this in mind when creating new actions, to avoid any kind of possible problems. | ||
=== The basic .actions file === | === The basic .actions file === | ||
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 KAuth actions in your application |
| 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.
Many authorization systems are quite strict about action naming, hence staying compatible with all of them is a tricky task. To ensure maximum compatibility with all of them, use, both in action namespaces and action names, only lowercase letters and numbers. Here comes a small example:
Please always keep this in mind when creating new actions, to avoid any kind of possible problems.
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.
Each .actions file can contain an unlimited set of actions, provided that they belong to the same action namespace. This is extremely important.
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:
.actions files can have a special group, [Domain], under which you can give out some more information about the action namespace you're defining. This is how it looks (all fields are optional):
[Domain] Name=The KAuth example series Icon=kauth-example URL=http://techbase.kde.org/
The fields are defined as follows:
Once you defined the actions in your file (remember you can define an unlimited number of actions in an .actions file, provided that they all belong to the same 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.