# NOT RUN {
server <- vaultr::vault_test_server(if_disabled = message)
if (!is.null(server)) {
root <- server$client()
# The userpass authentication backend is not enabled by default,
# so we need to enable it first
root$auth$enable("userpass")
# Then we can add users:
root$auth$userpass$write("alice", "p4ssw0rd")
# Create a new client and login with this user:
alice <- vaultr::vault_client(addr = server$addr)
# it is not recommended to login with the password like this as
# it will end up in the command history, but in interactive use
# you will be prompted securely for password
alice$login(method = "userpass",
username = "alice", password = "p4ssw0rd")
# Alice has now logged in and has only "default" policies
alice$auth$token$lookup_self()$policies
# (wheras our original root user has the "root" policy)
root$auth$token$lookup_self()$policies
}
# }
Run the code above in your browser using DataLab