### Install Authentication Zero Gem Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md Installs the Authentication Zero gem using Bundler. Specific versions are recommended for older Rails releases to ensure compatibility. ```bash $ bundle add authentication-zero ``` ```bash # For Rails < 7.2 $ bundle add authentication-zero --version "~> 3" ``` ```bash # For Rails < 7.1 $ bundle add authentication-zero --version "~> 2" ``` -------------------------------- ### Rails Authentication Core Components Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md Details key Rails components and methods utilized or generated by Authentication Zero for secure password handling, token generation, and session management. ```APIDOC ActiveModel::SecurePassword::ClassMethods#has_secure_password Adds methods to set and authenticate against a bcrypt password. Example: class User < ApplicationRecord has_secure_password end ActiveRecord::SecurePassword::ClassMethods#authenticate_by Given a set of attributes, finds a record using the non-password attributes, and then authenticates that record using the password attributes. Parameters: attributes: Hash of attributes to find and authenticate. Returns: The authenticated record or nil if authentication fails. ActiveRecord::TokenFor::ClassMethods#generates_token_for Defines the behavior of tokens generated for a specific purpose. Parameters: purpose: Symbol representing the purpose of the token (e.g., :email_verification). options: Hash of options, e.g., expires_after. ActionDispatch::Cookies#signed cookies Returns a jar that automatically generates a signed representation of cookie values and verifies them when reading. Helps mitigate tampering. ActionDispatch::Cookies#httponly cookies Sets the HttpOnly flag on cookies, making them inaccessible to client-side JavaScript. This is a security measure to mitigate cross-site scripting (XSS) attacks. ActiveRecord::SignedId#signed_id Returns a signed ID that is tamper-proof, suitable for sending in emails or sharing publicly. Parameters: id: The record ID to sign. purpose: Symbol representing the purpose of the signed ID. Returns: A signed, base64 encoded string. ActiveSupport::CurrentAttributes Abstract superclass that provides a thread-isolated attributes singleton, which resets automatically before and after each request. Useful for managing context-specific data like the current user. ActionMailer::Base Allows sending emails from your application using mailer models and views. Used for notifications like password resets and email verification. Log Filtering Parameters like 'token' and 'password' are automatically marked [FILTERED] in logs for security. Functional Tests Tests controller actions to verify application behavior. System Testing Tests user interactions with the application via a browser, ensuring end-to-end functionality. ``` -------------------------------- ### Release New Version (Development) Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md This command is used during development to release a new version of the gem. It involves updating the version number in `version.rb` and then executing a Rake task that handles git tagging, commit pushing, and gem publishing to rubygems.org. ```bash bundle exec rake release ``` -------------------------------- ### Configure Account Middleware (Rails) Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md This configuration snippet shows how to integrate the `AccountMiddleware` into your Rails application. It involves requiring the middleware file and then adding it to the application's middleware stack, typically in `config/application.rb`. ```ruby require_relative "../lib/account_middleware" # In config/application.rb or an initializer config.middleware.use AccountMiddleware ``` -------------------------------- ### Sudoable Feature Usage Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md Explains how to implement the 'sudoable' feature, which requires users to re-enter their password for sensitive actions after a period of inactivity or initial access. ```APIDOC Sudoable Feature Use `before_action :require_sudo` in controllers that handle sensitive information. This mechanism prompts the user for their password upon first access or after 30 minutes of inactivity. Example Controller Snippet: class SensitiveController < ApplicationController before_action :authenticate_user! before_action :require_sudo def edit_profile # ... sensitive action ... end end ``` -------------------------------- ### Generate Authentication System Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md Generates the authentication system code into your Rails application using the provided Rails generator command. ```bash $ rails generate authentication ``` -------------------------------- ### Include AccountScoped in Scoped Models (Rails) Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md This Ruby code demonstrates how to include the `AccountScoped` module in your Rails models. This module is responsible for setting up the necessary account relationship and applying a default scope based on the current account, ensuring data isolation. ```ruby include AccountScoped ``` -------------------------------- ### Add Account ID to Scoped Tables (Rails) Source: https://github.com/lazaronixon/authentication-zero/blob/main/README.md This snippet shows the Rails generator command to create a migration that adds an account reference to a table. This is a crucial step for implementing row-level multitenancy by associating records with specific accounts. ```bash rails g migration add_account_to_projects account:references ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.