Skip to content

Writing Plugin Permissions

The goal of this exercise is to get a better understanding on how plugin permissions can be created when writing your own plugin.

At the end you will have the ability to create simple permissions for your plugins. You will have an example Tauri plugin where permissions are partially autogenerated and hand crafted.

  1. In our example we will facilitate the Tauri cli to bootstrap a Tauri plugin source code structure. Make sure you have installed all Prerequisites and verify you have the Tauri CLI in the correct version by running cargo tauri info.

    The output should indicate the tauri-cli version is 2.x. We will proceed in this step-by-step explanation with pnpm but you can choose another package manager and replace it in the commands accordingly.

    Once you have a recent version installed you can go ahead and create the plugin using the Tauri CLI.

  2. To showcase something practical and simple let us assume our command writes user input to a file in our temporary folder while adding some custom header to the file.

    Let’s name our command write_custom_file, implement it in src/ and add it to our plugin builder to be exposed to the frontend.

    Tauri’s core utils will autogenerate allow and deny permissions for this command, so we do not need to care about this.

  3. The previous step was to write the actual command implementation. Next we want to expose it to the frontend so it can be consumed.

  4. As our plugin should expose the write_custom_file command by default we should add this to our default.toml permission.

  5. The created plugin directory structure contains an examples/tauri-app folder, which has a ready to use Tauri application to test out the plugin.

    Since we added a new command we need to slightly modify the frontend to invoke our new command instead.

© 2024 Tauri Contributors. CC-BY / MIT