### Run Project Locally Source: https://github.com/simple-jwt-login/website/blob/main/README.md This command starts the documentation website locally using Docker Compose. Ensure Docker and Docker Compose are installed and running before executing. ```bash docker-compose up ``` -------------------------------- ### Full Shortcode Example Source: https://github.com/simple-jwt-login/website/blob/main/docs/integrations/Google/05_Shortcode.mdx An example demonstrating the usage of the shortcode with all available customization options applied to style the 'Continue with Google' button. ```php [simple-jwt-login-oauth provider="google" background="#c8c8c8" color="#f2f2f2" width="250px" height="40px" border="1px dotted blue"] ``` -------------------------------- ### Sending JWT Examples Source: https://github.com/simple-jwt-login/website/blob/main/docs/Configuration.mdx Provides examples of how to send JWTs using cURL for different methods: in the Authorization header, as a query parameter, and within the request body. ```bash Sending JWT in header: curl -X POST "http://localhost/wp/v2/users" -H "Authorization: YOUR_JWT" ``` ```bash Sending JWT as query parameters: curl -X POST "http://localhost/wp/v2/users?jwt=YOUR_JWT" or curl -X POST "http://localhost?rest_route=/wp/v2/users&jwt=YOUR_JWT" ``` ```bash Sending JWT as request body: curl -X POST "http://localhost/wp/v2/users" -H "Content-type: application/json" -d '{"JWT":"JYOUR JWT"}' ``` -------------------------------- ### Navigate and Start React App Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-27-how_to_use_the_js_sdk.md Navigates into the newly created React application directory and starts the development server. This command is used to run the React app locally. ```bash cd my-app npm start ``` -------------------------------- ### Install Simple JWT Login SDK Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-25-release-js-sdk.md Instructions for installing the Simple JWT Login JavaScript SDK using npm or yarn package managers. ```bash npm install "simple-jwt-login" ``` ```bash yarn add "simple-jwt-login" ``` -------------------------------- ### Install Simple-JWT-Login SDK Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-27-how_to_use_the_js_sdk.md Installs the simple-jwt-login SDK using npm or yarn package managers. This is the initial step to integrate the SDK into your project. ```bash npm install "simple-jwt-login" ``` ```bash yarn add "simple-jwt-login" ``` -------------------------------- ### Full WordPress JWT Login Workflow Source: https://github.com/simple-jwt-login/website/blob/main/docs/code_examples/php/Register_and_get_token.md This comprehensive example demonstrates the complete process of using the Simple JWT Login plugin. It covers registering a new user, obtaining a JWT via authentication, and then using that JWT to create a new WordPress post. It includes a helper `call` function for making cURL requests. ```php "test". random_int(0, 10000). "@localhost.com", "password" => "my secret password", "first_name" => "my firstname", "last_name" => "my last name", ); try { // Step 1: Register User $result = call("POST", $domain . "?rest_route=/simple-jwt-login/v1/users", $data, $headers); $responseJSON = json_decode($result, true); if ($responseJSON === false) { throw new \Exception("Response is not a JSON:", $result); } var_dump($responseJSON); // In case of error, suscess will be false if (!$responseJSON['success']) { throw new \Exception($responseJSON['data']['message']); } $userID = $responseJSON['id']; // Step 2: Get a JWT $result = call("POST", $domain . "?rest_route=/simple-jwt-login/v1/auth", $data, $headers); $responseJSON = json_decode($result, true); if ($responseJSON === false) { throw new \Exception("Auth response is not a JSON:", $result); } // In case of error, suscess will be false if (!isset($responseJSON['success']) || !$responseJSON['success']) { $error = "Error while getting the JWT"; if (isset($responseJSON['data']['message'])) { $error .= $responseJSON['data']['message']; } throw new \Exception($responseJSON['data']['message']); } if (!isset($responseJSON['data']['jwt'])) { throw new \Exception("The JWT is missing from API Response."); } // Your new JWT that you can use in other endpoints $jwt = $responseJSON['data']['jwt']; // Step 3: Create a new WordPress post $headers = array( "Content-type: application/json", "Authorization: " . $jwt ); $data = array( "title" => "Post Title", "excerpt" => "test", ); $result = call("POST", $domain . "?rest_route=/wp/v2/posts", $data, $headers); $responseJSON = json_decode($result, true); // Final Step: Post have been created echo "Post have been created: " . print_r($responseJSON, true) . PHP_EOL; } catch (\Exception $exception) { echo "There was an error: " . $exception->getMessage() . PHP_EOL; } ``` -------------------------------- ### Reset Password Request Examples Source: https://github.com/simple-jwt-login/website/blob/main/docs/reset_password/Reset-Password.md Demonstrates how to trigger the password reset functionality using different tools and programming languages. ```bash curl -X POST https://simplejwtlogin.com/wp-json/simple-jwt-login/v1/users/reset_password \ -d '{"email":"test@simplejwtlogin.com", "AUTH_CODE": "123"}' ``` ```php $simpleJwtLogin = new \SimpleJwtLoginClient\SimpleJwtLoginClient( 'https://simplejwtlogin.com', '/simple-jwt-login/v1' ); $result = $simpleJwtLogin->resetPassword('email@simplejwtlogin.com', 'AUTH CODE'); ``` ```javascript var data = JSON.stringify({ "email":"test@simplejwtlogin.com", "code": "123", "new_password": "test" }); var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function() { if(this.readyState === 4) { console.log(this.responseText); } }); xhr.open("POST", "https://simplejwtlogin.com" + "/simple-jwt-login/v1/users/reset_password"); xhr.setRequestHeader("Content-Type", "application/json"); xhr.send(data); ``` -------------------------------- ### Shell Example for JWT Authentication Source: https://github.com/simple-jwt-login/website/blob/main/docs/auth/Authentication.md Demonstrates how to use `curl` in a shell environment to authenticate and obtain a JWT token. ```bash curl -X POST https://simplejwtlogin.com/?rest_route=/simple-jwt-login/v1/auth \ -d '{"email":"test@simplejwtlogin.com","password":"mySecretPassword"}' ``` -------------------------------- ### Request Body Example for User Registration Source: https://github.com/simple-jwt-login/website/blob/main/docs/Register-User.md An example JSON payload demonstrating the structure and fields required for registering a new user via the Simple JWT Login API. ```json { "email": "test@simplejwtlogin.com", "password": "string", "user_login": "myuser", "user_nicename": "myuser", "user_url": "https://simplejwtlogin.com", "display_name": "myuser", "nickname": "myuser", "first_name": "myuser", "last_name": "myuser", "description": "This is a sample description", "rich_editing": true, "syntax_highlighting": true, "comment_shortcuts": "falsec", "admin_color": "fresh", "use_ssl": true, "user_registered": "2022-01-31 23:15:30", "user_activation_key": "string", "spam": false, "show_admin_bar_front": true, "locale": "" } ``` -------------------------------- ### JWT Authentication Request Body Examples Source: https://github.com/simple-jwt-login/website/blob/main/docs/auth/Authentication.md Provides JSON examples for the request body of the JWT authentication endpoint, demonstrating different ways to provide user credentials. ```json { "email" : "test@simplejwtlogin.com", "password": "SomeSuperSecretPassword", "AUTH_CODE": "MySecretAuthCode" } ``` ```json { "username": "myuser", "password_hash" : "PasswordStoredInTheDB", "AUTH_CODE": "MySecretAuthCode" } ``` ```json { "login": "username or email", "password" : "SomeSuperSecretPassword", "AUTH_CODE": "MySecretAuthCode" } ``` -------------------------------- ### Allow JWT Usage on All Endpoints Example Source: https://github.com/simple-jwt-login/website/blob/main/docs/Configuration.mdx Illustrates how to use a JWT to authenticate as a specific user when creating posts via the WordPress API. It shows examples for sending the JWT in the request body and as a header. ```bash Creating posts with JWT in request body: curl -X POST "https://simplejwtlogin.com/wp-json/wp/v2/posts?content=PostContent&title=PostTitle" \ -d '{"JWT":"YOUR_JWT_HERE"}' ``` ```bash Creating posts with JWT in header: curl -X POST "https://simplejwtlogin.com/wp-json/wp/v2/posts" \ -H "Authorization: Bearer YOUR_JWT_HERE" \ --form title="Title" \ --form content="My content" \ --form type="page" ``` -------------------------------- ### PHP Example for User Registration Source: https://github.com/simple-jwt-login/website/blob/main/docs/Register-User.md A PHP code snippet demonstrating the usage of the SimpleJwtLoginClient to register a new user. ```php $simpleJwtLogin = new \SimpleJwtLoginClient\SimpleJwtLoginClient( 'https://simplejwtlogin.com', '/simple-jwt-login/v1' ); $result = $simpleJwtLogin->registerUser('email@simplejwtlogin.com', 'password', 'AUTH CODE'); ``` -------------------------------- ### Shell Example for User Registration Source: https://github.com/simple-jwt-login/website/blob/main/docs/Register-User.md A cURL command to demonstrate how to register a user using the Simple JWT Login API from the command line. ```bash curl -X POST 'https://simplejwtlogin.com/wp-json/simple-jwt-login/v1/users' \ -d '{"email":"myemail@simplejwtlogin.com", "password":"test"}' ``` -------------------------------- ### Package.json Dependencies Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-27-how_to_use_the_js_sdk.md Shows the relevant dependency in the package.json file after installing the simple-jwt-login SDK. This confirms the SDK has been successfully added to the project. ```json "dependencies": { "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-scripts": "5.0.1", "simple-jwt-login": "^0.1.4", "web-vitals": "^2.1.4" } ``` -------------------------------- ### PHP Example for JWT Authentication Source: https://github.com/simple-jwt-login/website/blob/main/docs/auth/Authentication.md Shows a PHP code snippet using the SimpleJwtLoginClient to authenticate a user and retrieve a JWT. ```php $simpleJwtLogin = new \SimpleJwtLoginClient\SimpleJwtLoginClient( 'https://simplejwtlogin.com', '/simple-jwt-login/v1' ); $result = $simpleJwtLogin->authenticate('email@simplejwtlogin.com', 'your password', 'AUTH CODE'); ``` -------------------------------- ### Autologin Request Example Source: https://github.com/simple-jwt-login/website/blob/main/docs/Login-User.md Provides a sample request URL for the autologin endpoint. ```APIDOC https://{{yoursite}}a/?rest_route=/simple-jwt-login/v1/autologin&JWT={{JWT}}&AUTH_KEY={{AUTH_KEY_VALUE}} ``` -------------------------------- ### JWT Authentication Response Examples Source: https://github.com/simple-jwt-login/website/blob/main/docs/auth/Authentication.md Illustrates the expected JSON responses for successful (200) and error (400) scenarios from the JWT authentication endpoint. ```json { "success": true, "data": { "jwt": "NEW_GENERATED_JWT_HERE" } } ``` ```json { "success": false, "error" : "Error message" } ``` -------------------------------- ### JWT Payload Example Source: https://github.com/simple-jwt-login/website/blob/main/docs/Login-User.md Illustrates a sample JWT payload structure, highlighting where user information like UserID might be located. ```json { "sub": "1234567890", "name": "John Doe", "UserID": 123456 } ``` -------------------------------- ### Restart Apache Service Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-26-CORS-setup.md Restarts the Apache web server to apply the configuration changes, including the newly enabled modules and updated virtual host settings. ```bash sudo service apache2 restart ``` -------------------------------- ### Enable Apache Headers Module Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-26-CORS-setup.md Enables the Apache 'headers' module, which is required for setting custom HTTP headers like those needed for CORS. ```bash sudo a2enmod headers ``` -------------------------------- ### Autologin API Endpoint Source: https://github.com/simple-jwt-login/website/blob/main/docs/Login-User.md Details the GET endpoint for autologin, including URL structure, required and optional parameters, and example usage. ```APIDOC METHOD: GET ENDPOINT: /simple-jwt-login/v1/autologin URL Example: https://{{yoursite}}/?rest_route=/simple-jwt-login/v1/autologin&JWT={{JWT}}&AUTH_KEY={{AUTH_KEY_VALUE}} Parameters: - JWT (required, string): Your JWT. - AUTH_CODE (optional, string): Auth Code from the "Auth codes" section. Required only if "Autologin require Auth code" is enabled. - redirectURL (optional, string): If provided, you will be redirected to this URL after successfully logged in. Parameters can be sent as query params. ``` -------------------------------- ### Initialize SimpleJWTLogin Client Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-27-how_to_use_the_js_sdk.md This snippet demonstrates how to initialize the SimpleJWTLogin client with your WordPress instance URL and the plugin's API namespace. ```javascript const simpleJwtLogin = new SimpleJwtLogin("http://localhost:88","/simple-jwt-login/v1"); ``` -------------------------------- ### Delete User Request Examples Source: https://github.com/simple-jwt-login/website/blob/main/docs/Delete-User.md Provides examples of how to call the delete user endpoint using cURL, PHP, and JavaScript. ```bash curl -X DELETE https://simplejwtlogin.com/simple-jwt-login/v1/users \ -d '{"JWT":"YOUR_JWT","AUTH_CODE":"SECRET_AUTH_CODE"}' ``` ```php $simpleJWT = new \SimpleJwtLoginClient\SimpleJwtLoginClient( 'https://simplejwtlogin.com', '/simple-jwt-login-v1' ); $simpleJWT->delete('Your JWT'); ``` ```javascript var data = JSON.stringify({ "JWT":"YOUR_JWT", "AUTH_CODE":"SECRET_AUTH_CODE" }); var xhr = new XMLHttpRequest(); xhr.withCredentials = true; xhr.addEventListener("readystatechange", function() { if(this.readyState === 4) { console.log(this.responseText); } }); xhr.open("DELETE", "https://simplejwtlogin.com" + "/simple-jwt-login/v1/users"); xhr.setRequestHeader("Content-Type", "application/json"); xhr.send(data); ``` -------------------------------- ### Register User with JavaScript SDK Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-25-release-js-sdk.md Example demonstrating how to use the Simple JWT Login JavaScript SDK to register a new user. It shows initializing the SDK with API details and calling the registerUser method with user parameters. ```javascript import { SimpleJwtLogin } from "simple-jwt-login"; const simpleJwtLogin = new SimpleJwtLogin( "http://your-domain.com", "/simple-jwt-login/v1", "AUTH_KEY" ); let params = { email: "me@mydomain.com", password: "my-secret-password", nickname: "coolnickname", }; let result = simpleJwtLogin.registerUser(params, "MY_AUTH_KEY"); ``` -------------------------------- ### Create React App Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-27-how_to_use_the_js_sdk.md Creates a new React project using create-react-app. This command sets up the basic project structure and dependencies for a React application. ```bash npx create-react-app my-app ``` -------------------------------- ### Download Add-on Source: https://github.com/simple-jwt-login/website/blob/main/docs/integrations/ExportImport.mdx Provides a direct link to download the export-import add-on zip file from GitHub. ```html
``` -------------------------------- ### Redirect URL with Variables Source: https://github.com/simple-jwt-login/website/blob/main/docs/Login-User.md Example of constructing a dynamic redirect URL using available user variables. ```html http://yourdomain.com?param1={{user_id}}¶m2={{user_login}} ``` -------------------------------- ### Basic React App Structure Source: https://github.com/simple-jwt-login/website/blob/main/blog/2022-10-27-how_to_use_the_js_sdk.md The initial structure of a React App's App.js file before modifications. This serves as a baseline for adding new components and functionality. ```javascript import logo from './logo.svg'; import './App.css'; function App() { return (
Edit src/App.js and save to reload.