/** * Awesomeness for 3rd party support * * Filter; determine_current_user * Other Filter: check_authentication * * This creates a hook in the determine_current_user filter that can check for a valid access_token * and user services like WP JSON API and WP REST API. * @param [type] $user_id User ID to * * @author Mauro Constantinescu Modified slightly but still a contribution to the project. */ public function _wo_authenicate_bypass($user_id) { if ($user_id && $user_id > 0) { return (int) $user_id; } /** Extra code but if the user is already logged in, there is no need to re query the DB */ $o = get_option('wo_options'); if ($o['enabled'] == 0) { return (int) $user_id; } require_once dirname(WPOAUTH_FILE) . '/library/OAuth2/Autoloader.php'; OAuth2\Autoloader::register(); $server = new OAuth2\Server(new OAuth2\Storage\Wordpressdb()); $request = OAuth2\Request::createFromGlobals(); if ($server->verifyResourceRequest($request)) { $token = $server->getAccessTokenData($request); if (isset($token['user_id']) && $token['user_id'] > 0) { return (int) $token['user_id']; // If the token key is there but the ID is either 0 or empty // we will assume it is a valid client access token and will need to investigate the // request further. } elseif (isset($token['user_id']) && $token['user_id'] === 0) { } } }
/** * Awesomeness for 3rd party support * * Filter; determine_current_user * Other Filter: check_authentication * * This creates a hook in the determine_current_user filter that can check for a valid access_token and * user services like WP JSON API and WP REST API. * @param [type] $o [description] * @return [type] [description] * * @author Mauro Constantinescu Modified slightly but still a contribution to the project. */ public function _wo_authenicate_bypass($user_id) { if ($user_id && $user_id > 0) { return (int) $user_id; } /** Extra code but if the user is already logged in, there is no need to re query the DB */ $o = get_option('wo_options'); if ($o['enabled'] == 0) { return (int) $user_id; } require_once dirname(WPOAUTH_FILE) . '/library/OAuth2/Autoloader.php'; OAuth2\Autoloader::register(); $server = new OAuth2\Server(new OAuth2\Storage\Wordpressdb()); $request = OAuth2\Request::createFromGlobals(); if ($server->verifyResourceRequest($request)) { $token = $server->getAccessTokenData($request); if (isset($token['user_id']) && $token['user_id'] > 0) { return (int) $token['user_id']; } } }
*/ $ext_methods = apply_filters("wo_endpoints", null); // Check to see if the method exists in the filter if (array_key_exists($method, $ext_methods)) { // If the method is is set to public, lets just run the method without if (isset($ext_methods[$method]['public']) && $ext_methods[$method]['public']) { call_user_func_array($ext_methods[$method]['func'], $_REQUEST); exit; } $response = new OAuth2\Response(); if (!$server->verifyResourceRequest(OAuth2\Request::createFromGlobals())) { $response->setError(400, 'invalid_request', 'Missing or invalid parameter(s)'); $response->send(); exit; } $token = $server->getAccessTokenData(OAuth2\Request::createFromGlobals()); if (is_null($token)) { $server->getResponse()->send(); exit; } do_action('wo_endpoint_user_authenticated', array($token)); call_user_func_array($ext_methods[$method]['func'], array($token)); exit; } /** * Server error response. End of line * @since 3.1.0 */ $response = new OAuth2\Response(); $response->setError(400, 'invalid_request', 'Unknown request'); $response->send();