Autologin
-
When I call the website via Get parameter with token I want to be logged in automatically.
Is there a function in the framework which validates from the token and returns the user id.
Unfortunately I did not find anything.I would have thought something like this code:
$user_id = WPO_Auth_Code::authenticate_token($_GET[‘token’]);Here is the code how I want to realize this:
add_action(‘init’, ‘authenticate_user_with_token’); function authenticate_user_with_token() { // Check if token is present in GET parameter if (isset($_GET[‘token’])) { // Load WP OAuth Server class if (!class_exists(‘WPO_Auth_Code’)) { require_once(‘wp-content/plugins/wp-oauth-server/includes/class-wpoauth-code.php’); } // Authenticate token and get user ID $user_id = WPO_Auth_Code::authenticate_token($_GET[‘token’]); // Check if user ID is valid if ($user_id) { // Set authentication cookie for the user wp_set_auth_cookie($user_id); } } }
- The topic ‘Autologin’ is closed to new replies.