LrAU
LrAU is a system to create easy authentication based systems within rust. Each users permissions are configured in toml, as shown below:
Toml permissions
Example
[[]]
= "/contacts"
= false
[[]]
= "/contacts/name"
= true
[[]]
= "/contacts/name/middle"
= false
[[]]
= "/contacts/name/last"
= true
[[]]
= "/admin"
= false
[[]]
= "/admin/passwords"
= true
= true
Breakdown
As you can see one specifies paths and then wether a user has authentication. By default a user does not have authentication, and so instead it must be explicitly specified wether they are. Then in sub paths one can change this authentication, as shown in the example of only giving a user access to a contacts name (see line 1-6). There is also mutability, where you can specify if a user has mutable access to something, or wether not they are read only. This, like everything else, is assumed off by default. It is only available if you already give the user authentication.
Simple Instructions
First specify an individual element in a permissions
array. In this you need to specify a path path
, and wether the user has permission auth
. Then you can specify mutability mut
.
# Create an array element
[[]]
# Specify the path
= "/contacts"
# Specify the authentication
= true
# Specify if they can mutate the contacts
= true
This creates a permission in the /contacts
path, where the user can both read and mutate it.
In Rust
Users
First time
The main struct you need to worry about is the User
struct, which represents a logged in user. On initial instantiation you must provide:
- An id/username.
- A password (in plain text when you give it, transferred into a hash using the Argon2 algorithm.)
- A
Permissions
struct, see the permission management section above/
From there the algorithm will generate a salt and hash it using Argon2id.
From then on
Now, after this data is saved to a file, this data can be retrieved and used in the 'raw' version of this struct. In this version you just pass the hash directly, using the same layout as above. new_basic
Logging in
With a user you can call the .log_in(&str: password)
message to attempt authentication. The password given is not hashed and is then hashed by the internals.
Matching authentication
In rust you can call the function User.get_valid_permissions()
given the parameters path
and mut
. The parameter path
is the path to the permission. Note that if not specified it will use the permission of any parents (or however far up the tree it has to go.) mut
is wether you need mutable permissions or not.
/// This function lets a user over the network modify a contacts name,
/// ensuring that they have permission
Features
- Serde
serde
. - Diesel
diesels-support
.