Title: | R Shiny Authentication Module |
---|---|
Description: | R Shiny Authentication Module which includes View, Controller and Data Layer. |
Authors: | Flippie Coetser [aut, cre] |
Maintainer: | Flippie Coetser <[email protected]> |
License: | file LICENSE |
Version: | 1.0.0.0000 |
Built: | 2025-03-13 05:17:52 UTC |
Source: | https://github.com/FlippieCoetser/Authenticate |
This function manages user authentication within a Shiny application. It sets up a module server for handling user interactions related to login, registration, and session management. It includes mechanisms to validate user inputs, manage user session states, and dynamically update UI elements based on the authentication state.
Controller( id, storage, user = shiny::reactiveValues(), title = "Authenticate", debug = FALSE )
Controller( id, storage, user = shiny::reactiveValues(), title = "Authenticate", debug = FALSE )
id |
A unique identifier for the Shiny module. |
storage |
A storage backend for managing user data. |
user |
An optional reactive values with cached user details. |
title |
A character string representing the title of the authentication dialog. |
debug |
A logical value indicating whether to print debug messages. |
The function creates a series of event observers and reactive expressions that:
Handle guest and registered user logins.
Manage user registration.
Authenticate user credentials.
Provide functionality for user logout and cancellation of operations.
Dynamically control the visibility of UI elements such as username display and login/logout buttons based on the user's authentication status.
Each user interaction is validated through a set of predefined validation functions, and the UI is updated accordingly to reflect the current state. Errors in user input are handled gracefully, providing modal dialogs to inform users of specific issues.
A Shiny module server function.
Creates a processor that utilizes an encryption service to handle password hashing operations within a model object. This processor relies on an external encryption service, passed as a parameter, to hash passwords using the service's specific cryptographic methods.
Encryption.Processor(service)
Encryption.Processor(service)
service |
An encryption service object that provides cryptographic functions,
such as password hashing. This service should include a |
A list of functions that perform operations on model data, specifically:
Set.Hash
Updates a model object with a hashed password. The model must have a hash
field and a salt
field. The password is hashed using the provided salt
and the hash function from the encryption service.
model
: The model object containing the user data.
password
: The plain text password to be hashed.
Returns the modified model object with the hashed password.
Creates an encryption service that provides cryptographic functionalities, specifically for hashing passwords. This service uses SHA-512 hashing algorithm to combine a password with a salt and generate a hashed output.
Encryption.Service()
Encryption.Service()
A list containing cryptographic functions, including:
Hash.Password
Combines a password with a salt and computes a SHA-512 hash.
password
: The plain text password to be hashed.
salt
: A string used to salt the password to enhance security.
Returns a hashed string using SHA-512 algorithm.
Orchestration Service used to:
Register User
Check Username
Authenticate User
Orchestrator(storage)
Orchestrator(storage)
storage |
The storage provider to use by orchestration service |
This component provides operations for managing user data in the storage.
User.Broker(storage)
User.Broker(storage)
storage |
The storage object used for data persistence. |
A list of operations for managing user data.
User Business Entity is a data.frame with the following attributes:
id
username
hash
salt
Both id and salt are UUIDs and auto-generated on instantiation.
User.Model(username)
User.Model(username)
username |
The username of the user |
Constructs a service layer for user management that integrates validation with database operations. This function provides an interface to add, retrieve, update, and delete user records, ensuring that all operations are preceded by appropriate validations.
User.Service(broker)
User.Service(broker)
broker |
An object that handles the data storage operations, typically a database
broker with methods like |
A list of functions that manage user data, ensuring validation and interaction with the data storage layer:
Add
Validates and adds a user to the database.
Retrieve
Retrieves all users from the database.
RetrieveById
Retrieves a user by their unique ID after validating the ID format.
Update
Validates and updates a user record in the database.
Delete
Deletes a user record from the database after validating the ID format.
Constructs a list of exception handling functions specifically for user validation. This function provides a standardized way to handle and throw exceptions related to user data integrity. Each exception function is designed to stop execution with a specific error message if invoked.
User.Validation.Exceptions()
User.Validation.Exceptions()
The available exceptions are:
User.NULL
: Triggered when a user object is expected but not provided.
Attribute.NULL
: Triggered when a required attribute of the user object
is missing.
A list of functions, each corresponding to a specific type of exception related to user validation. Functions are invoked with parameters controlling whether the exception should be thrown and provide custom error messages.
This function creates a suite of validators for checking the integrity of user data.
It encapsulates various checks to ensure that user objects meet expected criteria,
such as non-null values for essential attributes and specific format validations.
Each validator function is designed to throw a specific exception from
User.Validation.Exceptions
if the validation fails.
User.Validator()
User.Validator()
A list of validator functions, which includes:
User
Validates a complete user object by sequentially applying all individual attribute checks.
Exists
Checks if the user object is not NULL.
HasId
, HasUsername
, HasHash
, HasSalt
Ensures that each respective attribute is not NULL.
Id
Validates that the user ID is in UUID format.
This dataset contains user information for a sample application. Each record represents a user with a unique identifier, username, hashed password, and associated salt for additional security during the hashing process. This data can be used for authentication system examples, security demonstrations, or testing user management functionalities.
Users
Users
A data frame with 3 rows and 4 columns:
Unique identifier for the user, stored as a UUID string.
Email address used as the username.
SHA-512 hashed password, as a hex string, for user authentication.
UUID string used as a salt for the password hash.
Generated synthetic data.
This function creates a user interface for managing authentication displays within a Shiny application. It provides reactive UI elements that show the current user's username and offer login or logout actions depending on the user's authentication state.
View(id)
View(id)
id |
A unique identifier for the Shiny module which scopes the UI elements. |
The view consists of:
A username display that only appears if the user is logged in.
A login action link that is visible when the user is not logged in.
A logout action link that appears when the user is logged in.
The visibility of these elements is controlled by Shiny's server-side logic which outputs reactivity conditions. These conditions are set based on the user's authentication status, ensuring that UI elements reflect the current state appropriately.
A Shiny UI component that includes conditional panels for user authentication management.