CakeDC Users Plugin Documentation

repository·16.next-cake5·Indexed 19 days ago

https://github.com/cakedc/users

A comprehensive user management solution for CakePHP that handles the user lifecycle, including authentication (social, magic links, 2FA), authorization (RBAC), and administrative CRUD operations. It supports PHP 8.1+ and CakePHP 5.0+, providing features such as account lockout policies, password reset, and an AuthLink helper for conditional link display based on permissions.

Tokens
37.5K
Snippets
149
Records
184
Agent score
67%

What's inside CakeDC Users

  1. Overview of CakeDC Users plugin features

    16.next-cake5

    The CakeDC Users plugin provides a complete user management system for CakePHP applications. Key capabilities include:

    • User Lifecycle: Registration, email validation, profile management, and password reset.
    • Authentication: Login/Logout, "Remember Me" (Cookie), and Magic Link (one-click login).
    • Social Login: Support for Facebook, Twitter, Instagram, Google, LinkedIn (via OpenID Connect), Amazon, and GitHub.
    • Security & 2FA: Two-Factor Authentication via One-Time Password (OTP) or Webauthn (e.g., Yubico Key, TouchID), account lockout policies, password strength meters, and reCaptcha (v2/v3).
    • Authorization: Integrated Role-Based Access Control (RBAC) and Superuser support (requires CakeDC/auth).
    • Admin Management: Built-in CRUD functionality for managing users.
  2. Core features of the CakeDC Users plugin

    16.next-cake5

    The CakeDC Users plugin provides a comprehensive suite of authentication and user management capabilities, including:

    • Registration & Verification: User registration and account verification via email tokens.
    • Authentication: Standard email/password login, 'Remember Me' functionality via cookies, and Two-Factor Authentication (2FA).
    • Social Login: Support for Twitter, Facebook, Google, and Instagram.
    • Account Recovery: Password reset workflows using email-based tokens.
    • User Management: Administrative capabilities to add, edit, and delete users.
    • Authorization: Simple roles management, RBAC (Role-Based Access Control), and SuperUser authorization.
    • Security: reCaptcha integration for registration and login endpoints.
  3. Understand Social Middlewares and Authenticators

    16.next-cake5

    Social authentication relies on a combination of middlewares and authenticators:

    1. SocialAuthMiddleware + CakeDC/Users.Social (Authenticator): The primary flow used to redirect users to the provider and handle standard authentication.
    2. SocialEmailMiddleware + CakeDC/Users.SocialPendingEmail (Authenticator): Used when the social provider does not return the user's email address, triggering a flow to collect/validate it.
  4. How Two-Factor Authentication works

    16.next-cake5

    When enabled, the plugin integrates OTP authentication into the login flow.

    1. First-time setup: The user is presented with a QR code. They must scan this code using a Google Authenticator app (or similar TOTP app) to add your site.
    2. Verification: After providing credentials, the user is prompted to enter the current validation code generated by their authenticator app to complete the login.
  5. Extend the CakeDC Users plugin for custom implementations

    16.next-cake5
    While the CakeDC Users plugin provides a complete set of user management features out of the box, it is designed to be extended. Developers can inherit from the plugin's classes to create application-specific user implementations that suit their unique business logic or data requirements.
  6. Configure Authentication and Authorization

    16.next-cake5

    The plugin uses cakephp/authentication and cakephp/authorization by default. Most configuration is handled under the Auth key in config/users.php.

    To disable the automatic loading of the authorization service, use:

    'Auth.Authorization.enable' => false,

    For detailed configuration of the underlying authentication/authorization logic, refer to their respective documentation or the plugin's internal configuration file at vendor/cakedc/users/config/users.php.

  7. Understand the Permissions Model

    16.next-cake5

    The CakeDC Users plugin uses two primary policies to perform permission checks for all requests:

    1. Superuser policy: Allows the superuser to access any page regardless of other rules.
    2. Rbac (Role-Based Access Control) policy: Allows you to define specific rules in config/permissions.php to perform checks based on request information (such as prefix, plugin, controller, and action) and user data (such as role).
  8. Extend the Users Plugin

    16.next-cake5

    The Users plugin is designed as a base for your application. You should not use it exactly as-is, but rather extend its core components to fit your specific business logic.

    You can extend:

    • The Model: Customize the Table and Entity classes.
    • The Controller: Add custom logic to user management actions.
    • The Templates: Override default views by placing them in templates/plugin/CakeDC/Users/Users.

    For detailed instructions on how to perform these extensions, refer to the Extending the Plugin guide.

  9. Configure reCaptcha

    16.next-cake5

    To enable reCaptcha, register your site at the Google reCaptcha console, install the google/recaptcha package, and add the following keys to config/users.php:

    composer require google/recaptcha:@stable
    'Users.reCaptcha.key' => 'YOUR RECAPTCHA KEY',
    'Users.reCaptcha.secret' => 'YOUR RECAPTCHA SECRET',
    'Users.reCaptcha.version' => '2', // Use '3' for version 3 (recommended)
    'Users.reCaptcha.registration' => true, // Enable on registration
    'Users.reCaptcha.login' => true, // Enable on login