### Install PHP SDK Source: https://github.com/nicumicle/simple-jwt-login/blob/master/README.md Instructions for installing the PHP SDK for the Simple JWT Login plugin using Composer. This SDK simplifies integration with your PHP applications. ```shell composer require nicumicle/simple-jwt-login-client-php ``` -------------------------------- ### Install JavaScript SDK (npm) Source: https://github.com/nicumicle/simple-jwt-login/blob/master/README.md Instructions for installing the JavaScript SDK for the Simple JWT Login plugin using npm. This SDK facilitates integration with your JavaScript applications. ```shell npm install "simple-jwt-login" ``` -------------------------------- ### Install JavaScript SDK (yarn) Source: https://github.com/nicumicle/simple-jwt-login/blob/master/README.md Instructions for installing the JavaScript SDK for the Simple JWT Login plugin using yarn. This SDK facilitates integration with your JavaScript applications. ```shell yarn add "simple-jwt-login" ``` -------------------------------- ### Initialize Local Docker Environment Source: https://github.com/nicumicle/simple-jwt-login/blob/master/CONTRIBUTING.md Starts the Docker containers defined in the docker-compose.yaml file. This command is essential for setting up the local development environment required for the project. ```Shell docker-composer -f docker\docker-compose.yaml up ``` -------------------------------- ### Install Simple JWT Login Javascript SDK (npm) Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Installs the JavaScript SDK for the Simple JWT Login WordPress plugin using npm. This SDK facilitates client-side integration with your web applications. ```bash npm install "simple-jwt-login" ``` -------------------------------- ### JWT Payload Structure Example Source: https://github.com/nicumicle/simple-jwt-login/wiki/Login-User An example JSON structure for a JWT payload, demonstrating how user information like 'sub', 'name', and 'UserID' might be included. This structure helps in understanding how the plugin maps JWT claims to user data. ```json { "sub": "1234567890", "name": "John Doe", "UserID": 123456 } ``` -------------------------------- ### Install Simple JWT Login PHP Client Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Installs the official PHP client package for the Simple JWT Login WordPress plugin using Composer. This package simplifies integration with your PHP applications. ```bash composer require nicumicle/simple-jwt-login-client-php ``` -------------------------------- ### Install Simple JWT Login Javascript SDK (yarn) Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Installs the JavaScript SDK for the Simple JWT Login WordPress plugin using yarn. This SDK facilitates client-side integration with your web applications. ```bash yarn add "simple-jwt-login" ``` -------------------------------- ### Custom User Meta Example Source: https://github.com/nicumicle/simple-jwt-login/wiki/Register-User Demonstrates how to pass custom user meta data during user creation using a JSON object. ```JSON { "meta_key": "meta_value", "meta_key2": "meta_value" } ``` -------------------------------- ### Send Email After New User Creation Source: https://github.com/nicumicle/simple-jwt-login/wiki/Hooks Example demonstrating how to use the `simple_jwt_login_register_hook` to send a welcome email to a newly registered user, including their credentials. ```php add_action( 'simple_jwt_login_register_hook', function($user, $password){ $to = $user->user_email; $subject = 'Welcome'; $message = '\n Welcome to My Site. Your new user credentials are: \n email: ' . $to .'\n password: '. $password; wp_mail($to, $subject, $message); }, 10, 2); ``` -------------------------------- ### Dynamic Redirection URLs After Login Source: https://github.com/nicumicle/simple-jwt-login/wiki/Hooks This example utilizes the `simple_jwt_login_redirect_hook` to implement dynamic redirection based on a 'page' parameter passed in the login URL, allowing redirection to different sites. ```php add_action('simple_jwt_login_redirect_hook', function($url, $request){ $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null; if($page === null){ wp_redirect($url); return; } switch($page){ case "page1": wp_redirect('https://site1.com'); break; case "page2": wp_redirect('https://site2.com'); break; } },10,2); ``` -------------------------------- ### Redirect URL with Dynamic Variables Source: https://github.com/nicumicle/simple-jwt-login/wiki/Login-User An example of a custom redirect URL that utilizes dynamic variables provided by the plugin. These variables, such as {{user_id}} and {{user_login}}, are replaced with actual user data after a successful login. ```APIDOC Redirect URL Example: http://yourdomain.com?param1={{user_id}}¶m2={{user_login}} Description: This example shows how to construct a redirect URL that includes dynamic user information. The plugin replaces placeholders like `{{user_id}}` and `{{user_login}}` with the corresponding logged-in user's ID and username before redirecting. Available Variables: - `{{site_url}}`: Site URL - `{{user_id}}`: Logged in user ID - `{{user_email}}`: Logged in user email - `{{user_login}}`: Logged in username - `{{user_first_name}}`: User first name - `{{user_last_name}}`: User last name - `{{user_nicename}}`: User nice name Usage: Configure this URL in the plugin settings to redirect users to a personalized page after login. Ensure the 'Allow redirect to a specific URL' option is enabled. ``` -------------------------------- ### Simple JWT Login Autologin Endpoint Source: https://github.com/nicumicle/simple-jwt-login/wiki/Login-User Details the GET endpoint for the Simple JWT Login plugin's autologin functionality. It requires a JWT and an AUTH_KEY in the URL parameters to authenticate and log in users. ```APIDOC Endpoint: Simple JWT Login Autologin Method: GET URL: https://{{yoursite}}/?rest_route=/simple-jwt-login/v1/autologin&JWT={{JWT}}&AUTH_KEY={{AUTH_KEY_VALUE}} Description: This endpoint facilitates automatic user login using a JSON Web Token (JWT). The plugin validates the provided JWT and, upon successful validation, can extract user details like email or user ID from the JWT payload. Parameters: - JWT: The JSON Web Token for authentication. - AUTH_KEY: An authentication key, likely used for server-side verification or specific plugin configurations. Usage: Users must include their JWT and the AUTH_KEY as URL parameters when accessing this endpoint to trigger the autologin process. Note: The JWT can also be provided via Header, Cookie, or Session, with URL parameters taking precedence if present in multiple locations. ``` -------------------------------- ### Customize JWT Payload on /auth Endpoint Source: https://github.com/nicumicle/simple-jwt-login/wiki/Hooks Example showing how to use the `simple_jwt_login_jwt_payload_auth` filter to add custom data to the JWT payload when the `/auth` endpoint is accessed. ```php add_filter('simple_jwt_login_jwt_payload_auth',function($payload, $request){ $payload['myvalue'] = 'somevalue'; return $payload; },10, 2); ``` -------------------------------- ### IP Address Limiting Configuration Source: https://github.com/nicumicle/simple-jwt-login/wiki/Delete-User Example of how to configure IP addresses to limit user deletion operations for enhanced security. Multiple IP addresses can be specified, separated by commas. ```config 127.0.0.1, 123.123.123.123 ``` -------------------------------- ### User Registration with JWT Source: https://github.com/nicumicle/simple-jwt-login/blob/master/Changelog.md Shows how to register a new user and optionally receive a JWT in the response. ```APIDOC Endpoint: /register (POST) Request Body Example: { "username": "newuser", "email": "newuser@example.com", "password": "securepassword", "jwt_in_register": true, "role": "subscriber" } ``` -------------------------------- ### Run Unit Tests Source: https://github.com/nicumicle/simple-jwt-login/blob/master/CONTRIBUTING.md Executes the unit tests for the project using PHPUnit. The `--testsuite "Unit"` flag specifies the unit test suite, and `--coverage-text` generates a text-based code coverage report. ```PHP vendor/bin/phpunit --testsuite "Unit" --coverage-text ``` -------------------------------- ### JWT Handling and Configuration Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Details on how JWTs are handled, including options for storage, parameter inclusion, and case sensitivity. ```APIDOC JWT Handling: JWT Storage: - JWT can be obtained from '$_COOKIE' and '$_SESSION'. - JWT can be added in header. - Ignore case for JWT parameter. JWT Payload: - Option to add username in JWT payload. - Allow adding extra parameters in payload on /auth endpoint. JWT Parameters: - Key change for URL, Session, Cookie and Header parameters. - Add more variables for `redirectUrl`. - Add `redirectUrl` parameter. - Variables for URLs. JWT Algorithm: - Option to save JWT algorithm. - Allow usage of certificates in order to encode/decode JWT. ``` -------------------------------- ### Run Feature Tests Source: https://github.com/nicumicle/simple-jwt-login/blob/master/CONTRIBUTING.md Executes the feature tests for the project using PHPUnit. The `--testsuite "Feature"` flag specifies the feature test suite, and `--coverage-text` generates a text-based code coverage report. ```PHP vendor/bin/phpunit --testsuite "Feature" --coverage-text ``` -------------------------------- ### Plugin Hooks and Callbacks Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Details on available hooks for customizing plugin behavior, such as during login, registration, and user creation. ```APIDOC Plugin Hooks: - Hook for `No redirect` in order to customize the autologin response. - Add permission callback to api routes. - Add hooks for login, register and create User. - Add plain text password to register user hook. - Add more options for create new user. - Add more options when a new user is created. - Add a hook that is called before the user it is redirected to the page he specified in the login section. - Add initial request data to the hook simple_jwt_login_redirect_hook call. ``` -------------------------------- ### PHP: Filter to Customize No Redirect Response Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md This example shows how to use the `simple_jwt_login_no_redirect_message` filter. It enables customization of the response data when an auto-login action does not result in a redirect, allowing you to include additional user information like ID and details. ```PHP add_filter('simple_jwt_login_no_redirect_message',function($response, $request){ $response['userId'] = get_current_user_id(); $response['userDetails'] = wp_get_current_user(); return $response; },10, 2); ``` -------------------------------- ### Check Plugin with Composer Source: https://github.com/nicumicle/simple-jwt-login/blob/master/CONTRIBUTING.md Runs a predefined script from the composer.json file to perform checks on the plugin. This is a convenient way to ensure the plugin meets project standards and requirements. ```PHP composer check-plugin ``` -------------------------------- ### Error Handling and Settings Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Information on error reporting, settings management, and UI improvements for plugin configuration. ```APIDOC Error Handling and Settings: - Highlight Settings errors and display section. - Fix PHP warning for session_start(). - Improve error system from plugin settings. - Add codes to errors. - Fix validations. - Allow save in settings with no AUTH_KEYS when they are not used. - Fix issue with saving JWT algorithm. - Fix CORS issue. - Fix tabs visibility issue on some WordPress versions. - Attach plugin version to js and css. - Change the path for js and css files. - Change the load order for the JS files. - New UI for plugin configuration. - Allow users to enable/disable specific hooks. - Add a toggle for all hooks. ``` -------------------------------- ### Navigate to Development Directory Source: https://github.com/nicumicle/simple-jwt-login/blob/master/CONTRIBUTING.md Changes the current working directory inside the Docker container to '/var/www/dev'. This directory typically contains the project's development files and scripts. ```Shell cd /var/www/dev ``` -------------------------------- ### Create WordPress User API Endpoint Source: https://github.com/nicumicle/simple-jwt-login/wiki/Register-User This API endpoint allows for the creation of new WordPress users via a POST request. It requires authentication details and user credentials. ```APIDOC POST https://{{yoursite}}/?rest_route=/simple-jwt-login/v1/users&email={{email}}&password={{password}}&AUTH_KEY={{AUTH_KEY_VALUE}} Description: Creates a new WordPress user. Parameters: - email (required, string): The email address for the new user. - password (required, string): The plain-text password for the new user. - AUTH_KEY (required, string): The authentication key value for the request. - user_login (optional, string): The user’s login username. - user_nicename (optional, string): The URL-friendly user name. - user_url (optional, string): The user URL. - display_name (optional, string): The user’s display name. Defaults to the user’s username. - nickname (optional, string): The user’s nickname. Defaults to the user’s username. - first_name (optional, string): The user’s first name. Used to build the first part of the display name if display_name is not specified. - last_name (optional, string): The user’s last name. Used to build the second part of the display name if display_name is not specified. - description (optional, string): The user’s biographical description. - rich_editing (optional, string): Enables rich-editor for the user. Accepts 'true' or 'false'. Defaults to 'true'. - syntax_highlighting (optional, string): Enables rich code editor for the user. Accepts 'true' or 'false'. Defaults to 'true'. - comment_shortcuts (optional, string): Enables comment moderation keyboard shortcuts. Accepts 'true' or 'false'. Defaults to 'false'. - admin_color (optional, string): Admin color scheme for the user. Defaults to 'fresh'. - use_ssl (optional, bool): Whether the user should always access the admin over https. Defaults to false. - user_registered (optional, string): Date the user registered. Format is 'Y-m-d H:m:s'. - user_activation_key (optional, string): Password reset key. Defaults to empty. - spam (optional, bool): Multisite only. Whether the user is marked as spam. Defaults to false. - show_admin_bar_front (optional, string): Whether to display the Admin Bar on the site’s front end. Accepts 'true' or 'false'. Defaults to 'true'. - locale (optional, string): User’s locale. Defaults to empty. - user_meta (optional, JSON): Custom user meta data to add. Example: {"meta_key":"meta_value"} User Types: The plugin supports creating users with specific roles: - editor - author - contributor - subscriber - any custom role configured in WordPress Example Request Body (Conceptual): POST /simple-jwt-login/v1/users?email=test@example.com&password=securepassword&AUTH_KEY=YOUR_AUTH_KEY (Additional parameters can be appended as query parameters or potentially in a JSON body depending on implementation) Note: The exact method of passing parameters (query string vs. JSON body) might vary based on the plugin's specific implementation of the REST API endpoint. ``` -------------------------------- ### Connect to Docker Container Source: https://github.com/nicumicle/simple-jwt-login/blob/master/CONTRIBUTING.md Executes an interactive bash shell within the specified Docker container ('wordpress'). This allows direct access to the container's filesystem and processes for debugging or running commands. ```Shell docker exec -it wordpress /bin/bash ``` -------------------------------- ### User Registration API Parameters Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Defines the parameters accepted during user registration via the plugin's API. This includes essential fields like email and password, along with optional user profile details and meta information. ```APIDOC User Registration Parameters: - email: (required) (string) The user email address. - password: (required) (string) The plain-text user password. - user_login: (string) The user's login username. - user_nicename: (string) The URL-friendly username. - user_url: (string) The user URL. - display_name: (string) The user's display name. Default is the user's username. - nickname: (string) The user's nickname. Default is the user's username. - first_name: (string) The user's first name. Used to build the first part of the display name if not specified. - last_name: (string) The user's last name. Used to build the second part of the display name if not specified. - description: (string) The user's biographical description. - rich_editing: (string) Enable rich-editor. Accepts 'true' or 'false'. Default 'true'. - syntax_highlighting: (string) Enable rich code editor. Accepts 'true' or 'false'. Default 'true'. - comment_shortcuts: (string) Enable comment moderation keyboard shortcuts. Accepts 'true' or 'false'. Default 'false'. - admin_color: (string) Admin color scheme. Default 'fresh'. - use_ssl: (bool) User should always access admin over https. Default false. - user_registered: (string) Date the user registered. Format is `Y-m-d H:m:s`. - user_activation_key: (string) Password reset key. Default empty. - spam: (bool) Multisite only. Mark user as spam. Default false. - show_admin_bar_front: (string) Display Admin Bar on site's front end. Accepts 'true' or 'false'. Default 'true'. - locale: (string) User's locale. Default empty. - user_meta: (object) Custom meta data for the user. Example: {"meta_key":"meta_value", "meta_key2":"meta_value"} ``` -------------------------------- ### IP Restriction Configuration Source: https://github.com/nicumicle/simple-jwt-login/blob/master/Changelog.md Explains how to configure IP limitations for authentication. ```APIDOC Configuration Option: - IP limitation for Authentication Supported Formats: - Single IP: "192.168.1.100" - CIDR Notation: "192.168.1.0/24" - Wildcard: "192.168.*.100" - Multiple IPs/Ranges: Comma-separated list. ``` -------------------------------- ### User Registration via API Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Enables creating new WordPress users through API requests. Users can specify the new user's role, password handling, and post-registration actions. Registration can be limited by IP address or email domain. ```APIDOC User Registration Endpoint: - Method: POST - Parameters: - email: The email address for the new user (required). - password: The password for the new user (optional if 'Generate a random password' is enabled). - User Role Selection: - Allows specifying the role for the new user (e.g., editor, author, contributor, subscriber). - Password Generation: - Option: 'Generate a random password when a new user is created'. If enabled, password is not required in the request. - Post-Registration Actions: - Option: 'Initialize force login after register'. If enabled, the user will be automatically logged in after registration, following the configured login flow. - Restrictions: - IP Address Limit: User creation can be restricted to specific IP addresses. - Email Domain Limit: User creation can be restricted to specific email domains. ``` -------------------------------- ### PHP: Hook for Sending Email on User Registration Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md This code snippet demonstrates how to use the `simple_jwt_login_register_hook` action. It allows you to execute custom code after a new user is registered via the plugin, such as sending a welcome email with their credentials. ```PHP add_action( 'simple_jwt_login_register_hook', function($user, $password){ $to = $user->user_email; $subject = 'Welcome'; $message = '\n Welcome to My Site. Your new user credentials are: \n email: ' . $to .'\n password: '. $password; wp_mail($to, $subject, $message); }, 10, 2); ``` -------------------------------- ### User Meta and Roles Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Details on managing user metadata and roles within the authentication system. ```APIDOC User Management: - Fix user_meta URL encoded. - Add support for user_meta on create user. - Fix user role `None` when empty role in Auth Codes. - Add expiration date and user role to AUTH Codes. ``` -------------------------------- ### JWT Authentication Endpoints Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Provides documentation for key API endpoints related to JWT authentication, including token generation, validation, and user management operations. ```APIDOC API Endpoints: /auth (POST) - Authenticates a user and returns a JWT. - Allows adding extra parameters in payload. - Supports authentication with WordPress username. - Parameters: - username: User's WordPress username. - password: User's password. - [extra_parameters]: Optional parameters to include in the JWT payload. - Returns: JWT token and user details. /auth/revoke (POST) - Revokes a JWT token. - Parameters: - token: The JWT token to revoke. - Returns: Success or failure message. /auth/validate (GET) - Validates a JWT token and returns user details. - Parameters: - token: The JWT token to validate. - Returns: User details if the token is valid, otherwise an error. /register (POST) - Registers a new user. - Allows adding a JWT in the register user endpoint. - Supports user_meta on create user. - Parameters: - username: New user's username. - email: New user's email. - password: New user's password. - [user_meta]: Optional user metadata. - [jwt_option]: Option to add JWT during registration. - Returns: User creation status and details. /create-user (POST) - Creates a new user with various options. - Parameters: - username: New user's username. - email: New user's email. - password: New user's password. - [options]: Additional parameters for user creation (e.g., role, user_meta). - Returns: User creation status and details. /delete-user (POST) - Deletes a user by username. - Parameters: - username: The username of the user to delete. - Returns: User deletion status. /jwt-generator (GET) - Generates a JWT token. - Returns: A generated JWT token. /jwt-refresh (GET) - Refreshes an expired JWT token. - Parameters: - token: The expired JWT token. - Returns: A new JWT token. /api/routes (GET) - Retrieves information about available API routes. - Allows custom namespace for API routes. - Returns: List of API routes. ``` -------------------------------- ### Simple JWT Login Plugin Hooks Source: https://github.com/nicumicle/simple-jwt-login/wiki/Hooks This section details the action and filter hooks available in the Simple JWT Login plugin. These hooks allow developers to integrate custom logic at various stages of the authentication and user management process, such as after login, before redirection, or when modifying JWT payloads. ```APIDOC simple_jwt_login_login_hook: type: action parameters: - name: $user type: Wp_User description: The user object of the logged-in user. description: This hook is called after the user has been successfully logged in. simple_jwt_login_redirect_hook: type: action parameters: - name: $url type: string description: The default redirect URL. - name: $request type: array description: The request parameters. description: This hook is called before the user is redirected to a specified page after login. It allows for dynamic redirection logic. simple_jwt_login_register_hook: type: action parameters: - name: $user type: Wp_User description: The user object of the newly created user. - name: $plain_text_password type: string description: The plain text password for the new user. description: This hook is called immediately after a new user account has been created. simple_jwt_login_delete_user_hook: type: action parameters: - name: $user type: Wp_User description: The user object of the deleted user. description: This hook is called right after a user account has been deleted. simple_jwt_login_jwt_payload_auth: type: filter parameters: - name: $payload type: array description: The JWT payload to be returned. - name: $request type: array description: The request parameters. return: type: array description: The modified JWT payload. description: This hook is called on the /auth endpoint. It allows modification of the JWT payload parameters before it is returned. simple_jwt_login_no_redirect_message: type: filter parameters: - name: $payload type: array description: The payload associated with the no-redirect message. - name: $request type: array description: The request parameters. return: type: array description: The modified payload. description: This hook is called on the /autologin endpoint when the 'No Redirect' option is selected. It allows customization of the message and addition of parameters. ``` -------------------------------- ### Security and Encryption Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Information on security features like decryption key management and certificate usage. ```APIDOC Security Features: - Allow users to set decryption key in WordPress PHP code. - Allow users to store base64 encoded decryption keys and use them as decoded when needed. - Allow usage of certificates in order to encode/decode JWT. ``` -------------------------------- ### JWT Authentication and User Login Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Details how to authenticate users using JWT via various methods (URL, Header, Cookie, Session) and configure post-login redirects with dynamic variables. Supports multiple JWT decryption algorithms like HS256, HS512, RS256, etc. ```APIDOC JWT Authentication Methods: - JWT can be provided via: URL, Header, Cookie, or Session. - If JWT is present in multiple locations, the last one processed will overwrite previous ones. JWT Decryption Algorithms: - Supported algorithms include: HS256, HS512, HS384, RS256, RS384, RS512. Post-Login Redirect Configuration: - Redirect to: Dashboard, Homepage, or a custom page. - Custom Redirect URL Parameter: 'redirectUrl' can be used to specify a custom redirect destination. - Dynamic Redirect Variables: - {{site_url}}: The URL of the website. - {{user_id}}: The ID of the logged-in user. - {{user_email}}: The email address of the logged-in user. - {{user_login}}: The username of the logged-in user. - {{user_first_name}}: The first name of the logged-in user. - {{user_last_name}}: The last name of the logged-in user. - {{user_nicename}}: The nicename of the logged-in user. - Example URL with variables: http://yourdomain.com?param1={{user_id}}¶m2={{user_login}} IP Address Restriction: - Auto-login can be restricted to specific client IP addresses for enhanced security. ``` -------------------------------- ### WordPress Plugin Core Functionality (PHP) Source: https://github.com/nicumicle/simple-jwt-login/wiki/Home This snippet illustrates the core PHP functions and hooks used by the Simple JWT Login plugin to manage user authentication, registration, and deletion within a WordPress environment. ```php run(); } run_simple_jwt_login(); /** * Registers the API routes. * * @since 1.0.0 */ function register_simple_jwt_login_api() { $api = new Simple_JWT_Login_API(); $api->register_routes(); } add_action( 'rest_api_init', 'register_simple_jwt_login_api' ); // Example of a hook for auto-login functionality (conceptual) // add_action( 'wp_login', 'simple_jwt_login_handle_auto_login', 10, 2 ); // function simple_jwt_login_handle_auto_login( $user_login, $user ) { // // Logic to check for JWT and potentially re-authenticate or set cookies // } // Example of IP/Domain restriction check (conceptual) // function simple_jwt_login_check_restrictions( $action ) { // // Logic to check $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_HOST'] against plugin settings // return true; // or false if restricted // } ?> ``` -------------------------------- ### API Endpoints for JWT Authentication Source: https://github.com/nicumicle/simple-jwt-login/wiki/Home This section outlines the core API functionalities provided by the Simple JWT Login plugin for managing user authentication and data within WordPress. It covers user registration, login, and deletion via JWT. ```APIDOC API Endpoints: 1. User Registration: - Method: POST - Endpoint: /wp-json/simple-jwt-login/v1/register - Description: Registers a new user in WordPress. - Parameters: - username (string, required): The desired username for the new user. - email (string, required): The email address for the new user. - password (string, required): The password for the new user. - ip_address (string, optional): The IP address from which the request originates (for IP-based restrictions). - domain_name (string, optional): The domain name from which the request originates (for domain-based restrictions). - Returns: - JSON object containing success status and user details upon successful registration. - JSON object with error message upon failure. 2. User Login (Auto-login via JWT): - Method: GET or POST - Endpoint: /wp-json/simple-jwt-login/v1/login - Description: Authenticates a user using JWT and potentially logs them in automatically. - Parameters: - jwt (string, required): The JSON Web Token for authentication. - retrieve_jwt_from (string, optional): Specifies where to retrieve the JWT (e.g., 'url', 'session', 'cookie', 'header'). Defaults to header. - pass_request_parameters (string, optional): Allows passing request parameters to the login URL. - ip_address (string, optional): The IP address from which the request originates. - domain_name (string, optional): The domain name from which the request originates. - Returns: - JSON object indicating successful authentication and user information. - JSON object with error message upon failure. 3. User Deletion via JWT: - Method: DELETE - Endpoint: /wp-json/simple-jwt-login/v1/users/{user_id} - Description: Deletes a WordPress user based on a provided JWT for authorization. - Parameters: - user_id (integer, required): The ID of the user to delete. - jwt (string, required): The JSON Web Token for authorization. - ip_address (string, optional): The IP address from which the request originates. - domain_name (string, optional): The domain name from which the request originates. - Returns: - JSON object confirming user deletion. - JSON object with error message upon failure. 4. JWT Generation: - Method: POST - Endpoint: /wp-json/simple-jwt-login/v1/generate-token - Description: Generates a new JWT for a user. - Parameters: - username (string, required): The username for whom to generate the token. - password (string, required): The password for the user. - ip_address (string, optional): The IP address from which the request originates. - domain_name (string, optional): The domain name from which the request originates. - Returns: - JSON object containing the newly generated JWT. - JSON object with error message upon failure. Related Features: - Auto-login using JWT and AUTH_KEY. - Allow auto-login / register / delete users only from specific IP addresses. - Allow register users only from a specific domain name. - CORS settings for plugin Routes. - JWT Authentication. - Beta: Allow access to private endpoints with JWT. ``` -------------------------------- ### User Authentication and Authorization Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Covers various methods for user authentication, including username/password login, IP limitations, and force login options. ```APIDOC Authentication Features: Login Methods: - Allow login by username ( user_login ). - Users can authenticate with WordPress username for /auth endpoint. IP Restrictions: - Add IP limitation for Authentication. - Support for '*' in IP restrictions. Force Login: - Support for Force Login plugin. - Option 'Initialize force login after register' for auto-login flow after registration. Redirect Options: - Add `No Redirect` option for autologin and respond with a json on this endpoint. - Add a hook that is called before the user is redirected to the page specified in the login section. - Include request parameters used for login link in the REDIRECT URL. - Add initial request data to the hook simple_jwt_login_redirect_hook call. ``` -------------------------------- ### Password Reset Functionality Source: https://github.com/nicumicle/simple-jwt-login/blob/master/Changelog.md Describes the API endpoints for initiating and sending password reset links. ```APIDOC Endpoints: - /reset-password (POST) - /send-reset-password (POST) Request Body Example (for /reset-password): { "username": "user_to_reset" } ``` -------------------------------- ### JWT Generation Route Source: https://github.com/nicumicle/simple-jwt-login/blob/master/Changelog.md Mentions a dedicated route for generating JWTs, likely for testing or administrative purposes. ```APIDOC Route: JWT Generator - Purpose: Generate JWT tokens. ``` -------------------------------- ### Simple JWT Login Plugin API Endpoints Source: https://github.com/nicumicle/simple-jwt-login/blob/master/README.md This section outlines the core REST API endpoints provided by the Simple JWT Login plugin for authentication, user management, and security features. It details the functionality of each endpoint, including parameters and expected behavior for generating, validating, and revoking JWTs, as well as user registration, deletion, and password resets. ```APIDOC Simple JWT Login Plugin API: Features: - Authenticate: REST endpoint that will generate/validate/revoke a JWT. - Autologin: Autologin to a WordPress website with JWT. - Register user: Register users in WordPress by calling a REST endpoint. - Delete user: Delete a WordPress user by adding some details in the JWT payload. - Reset password: REST endpoint that allows you to reset WordPress User password. Also, it can send custom email if you want. - Protect endpoints: Protect WordPress endpoints with a JWT. - Allow JWT usage on other endpoints: Add a JWT to requests for other API endpoints. - Google OAuth (beta): Login to your website with Google. - Google JWT (beta): Use the Google `id_token` in order to access WordPress endpoints as an authenticated user. Setup Configuration: 1. General Section: - JWT Decryption key: Key used to validate the JWT. - JWT Decryption algorithm: Algorithm used for JWT decryption. 2. Login Section: - JWT parameter key: The payload key where the user can be identified. Note: Specific endpoint URLs, request methods (POST, GET, etc.), request bodies, and response formats are detailed in the plugin's external documentation at simplejwtlogin.com. ``` -------------------------------- ### Simple-JWT-Login Plugin Error Codes Source: https://github.com/nicumicle/simple-jwt-login/wiki/Error-Codes This section details the error codes encountered when using the Simple-JWT-Login plugin. Each entry includes the error code, a brief message, and a more comprehensive description of the potential cause or scenario. ```APIDOC Simple-JWT-Login Plugin Error Codes: Error Code 1: Key may not be empty Description: JWT is missing from request. Error Code 2: Wrong number of segments Description: The JWT contains 3 parts, separated by dots (Header, Payload, Signature). Your JWT does not have 2 dots in it. Error Code 3: Invalid header encoding Description: The encoding of the first part of the JWT is invalid. This means the first part of your JWT is incorrect. Error Code 4: Invalid claims encoding Description: The second part of your JWT is invalid. Error Code 5: Invalid signature encoding Description: The signature provided in "JWT Decryption key" is invalid. Error Code 6: Empty algorithm Description: Your JWT has no algorithm specified. Error Code 7: Algorithm not supported Description: The algorithm present in your JWT is not supported by this plugin. Error Code 8: Algorithm not allowed Description: The provided algorithm is not allowed by this plugin. Error Code 9: 'kid' invalid, unable to lookup correct key Description: Your JWT is malformed. Error Code 10: 'kid' invalid, unable to lookup correct key Description: Your JWT is malformed. Error Code 11: Signature verification failed Description: Invalid "JWT Decryption key" provided in config. Error Code 12: Cannot handle token prior to ... Description: Check that this token has been created before 'now'. Timestamp verified from 'nbf'. Error Code 13: Cannot handle token prior to ... Description: Check that this token has been created before 'now'. This prevents. Timestamp verified from 'iat'. Error Code 14: Expired token Description: JWT is expired. Error Code 15: Algorithm not supported Description: Algorithm not supported when JWT was signed. Error Code 16: OpenSSL unable to sign data Description: Error while JWT is signed with OpenSSL. Error Code 17: Unsupported sign function Description: Invalid Algorithm provided for JWT when signing. Error Code 18: Algorithm not supported Description: Invalid Algorithm while trying to verify the JWT. Error Code 19: OpenSSL error Description: This is a generic OpenSSL error. Error Code 20: Null result with non-null input Description: Decoded JWT is null. Error Code 21: Null result with non-null input Description: Encoded JWT is null. Error Code 22: Unknown JSON error Description: This is a generic error by JWT. More details are provided in the message. Error Code 23: Wrong Request. Description: JWT is missing in the auto-login process. Error Code 24: User not found. Description: This error occurs when the user is not found. For login and delete endpoint: there is no user in WordPress with the email or ID provided in JWT. Error Code 26: Auto-login is not enabled on this website. Description: You have to enable auto-login from plugin settings. Error Code 27: Invalid Auth Code provided. Description: The Auth code provided is invalid or missing. You should use one that you have saved in your plugin settings. Error Code 28: This IP is not allowed to auto-login. Description: You cannot auto-login from this IP. Some IPs are specified in plugin settings that can auto-login into WordPress. Error Code 29: Unable to find property in JWT. Description: The user sub-key property cannot be found in JWT. Error Code 30: Unable to find property in JWT. Description: The user key property cannot be found in JWT. Error Code 31: Register is not allowed. Description: Register is disabled from settings. Error Code 32: Invalid Auth Code Description: Invalid auth code provided on register endpoint. You can use auth codes that are generated in your plugin settings. Error Code 33: This IP is not allowed to register users. Description: You cannot register users from this IP. The allowed IPs are saved in plugin settings. Error Code 35: Missing email or password. Description: Missing email or password from your register new user request. Error Code 36: Invalid email address. Description: The value provided for email is not a valid email. Error Code 37: This website does not allow users from this domain. Description: The email domain is not allowed to register to this WordPress. The allowed domains are saved in plugin settings. Error Code 38: User already exists. Description: The user that you are trying to create already exists. Try a different email address. Error Code 39: Delete is not enabled. Description: The plugin delete endpoint is not enabled for this website. This can be enabled from plugin settings. Error Code 40: Missing AUTH KEY Description: Missing Auth Key from Delete. You can find your generated auth keys in plugin settings. Error Code 41: You are not allowed to delete users from this IP Description: You cannot delete users only from the IPs that are set in plugin settings. Error Code 42: The 'jwt' parameter is missing. Description: The JWT parameter is missing from the request. ``` -------------------------------- ### Dashboard and Auth Codes Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Features related to the plugin's dashboard, including displaying auth codes and IP limitations. ```APIDOC Dashboard Features: - Add Auth codes to dashboard. - Add Auth code on Authentication endpoint. - Display number of active hooks on dashboard. ``` -------------------------------- ### JWT Payload Customization Source: https://github.com/nicumicle/simple-jwt-login/blob/master/Changelog.md Demonstrates how to add extra parameters to the JWT payload during authentication requests. ```APIDOC Endpoint: /auth (POST) Request Body Example: { "username": "testuser", "password": "password123", "extra_parameters": { "user_role": "editor", "custom_field": "value" } } ``` -------------------------------- ### Simple JWT Login API Endpoints Source: https://github.com/nicumicle/simple-jwt-login/wiki/Authentication This API allows for JWT generation, refresh, validation, and revocation using WordPress user credentials. It requires POST requests to specific routes within the WordPress REST API. Successful authentication returns a JWT, while other operations manage token lifecycle. ```APIDOC Simple JWT Login API: This API provides endpoints for managing JSON Web Tokens (JWT) within a WordPress environment. 1. **Authenticate User (Generate JWT)** * **Method:** POST * **URL:** `https://{{yoursite}}/?rest_route=/simple-jwt-login/v1/auth` * **Parameters (in request body or query string):** * `email` (string, required): The WordPress user's email address. * `password` (string, required): The WordPress user's password. * **Description:** Generates a new JWT for the provided user credentials. * **Success Response Example:** ```json { "success": true, "data": { "jwt": "NEW_GENERATED_JWT_HERE" } } ``` * **Error Response:** Indicates authentication failure or invalid credentials. 2. **Refresh Token** * **Method:** POST * **URL:** `https://{{yoursite}}/?rest_route=/simple-jwt-login/v1/auth/refresh` * **Parameters (in request body or query string):** * `JWT` (string, required): The current, potentially expired, JWT. * **Description:** Refreshes an expired JWT, returning a new valid token if the original is still considered refreshable. * **Return Value:** A new JWT upon successful refresh. 3. **Validate Token** * **Method:** POST * **URL:** `https://{{yoursite}}/?rest_route=/simple-jwt-login/v1/auth/validate` * **Parameters (in request body or query string):** * `JWT` (string, required): The JWT to validate. * **Description:** Checks the validity of a given JWT. Returns user details and JWT information if valid. * **Return Value:** User details and JWT metadata if the token is valid. 4. **Revoke Token** * **Method:** POST * **URL:** `https://{{yoursite}}/?rest_route=/simple-jwt-login/v1/auth/revoke` * **Parameters (in request body or query string):** * `JWT` (string, required): The JWT to revoke. * **Description:** Invalidates a JWT, preventing its future use. This is typically used for logout functionality. * **Return Value:** Confirmation of revocation. ``` -------------------------------- ### Simple JWT Login Plugin Hooks Source: https://github.com/nicumicle/simple-jwt-login/blob/master/simple-jwt-login/README.md Details the available hooks within the Simple JWT Login WordPress plugin for advanced customization. These hooks allow developers to execute custom scripts at specific points in the plugin's lifecycle. ```APIDOC simple_jwt_login_login_hook: type: action parameters: Wp_User $user description: Called after a user has been successfully logged in. simple_jwt_login_redirect_hook: type: action parameters: string $url, array $request description: Called before a user is redirected to their specified page after login. simple_jwt_login_register_hook: type: action parameters: Wp_User $user, string $plain_text_password description: Called after a new user account has been created. simple_jwt_login_delete_user_hook: type: action parameters: Wp_User $user description: Called immediately after a user account has been deleted. simple_jwt_login_jwt_payload_auth: type: filter parameters: array $payload, array $request return: array $payload description: Allows modification of the JWT payload on the /auth endpoint. simple_jwt_no_redirect_message: type: filter parameters: array $payload, array $request return: array $payload description: Customizes the message for the 'No Redirect' option on the /autologin endpoint. simple_jwt_reset_password_custom_email_template: type: filter parameters: string $template, array $request return: string $template description: Replaces the default email template used for password reset requests via POST /user/reset_password. ```