| Server IP : 87.229.120.60 / Your IP : 216.73.216.245 Web Server : Apache System : Linux outside 5.4.8_Algonet_ZeroMAC_0.9.4.8 #6 SMP Mon Feb 3 20:36:07 CET 2020 x86_64 User : server ( 1002) PHP Version : 8.3.20 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,curl_multi_exec,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/faktorteam/www/wp-content/plugins/wordpress-seo/src/actions/semrush/ |
Upload File : |
<?php
namespace Yoast\WP\SEO\Actions\SEMrush;
use Yoast\WP\SEO\Config\SEMrush_Client;
use Yoast\WP\SEO\Exceptions\OAuth\Authentication_Failed_Exception;
/**
* Class SEMrush_Login_Action
*/
class SEMrush_Login_Action {
/**
* The SEMrush_Client instance.
*
* @var SEMrush_Client
*/
protected $client;
/**
* SEMrush_Login_Action constructor.
*
* @param SEMrush_Client $client The API client.
*/
public function __construct( SEMrush_Client $client ) {
$this->client = $client;
}
/**
* Authenticates with SEMrush to request the necessary tokens.
*
* @param string $code The authentication code to use to request a token with.
*
* @return object The response object.
*/
public function authenticate( $code ) {
// Code has already been validated at this point. No need to do that again.
try {
$tokens = $this->client->request_tokens( $code );
return (object) [
'tokens' => $tokens->to_array(),
'status' => 200,
];
} catch ( Authentication_Failed_Exception $e ) {
return $e->get_response();
}
}
/**
* Performs the login request, if necessary.
*/
public function login() {
if ( $this->client->has_valid_tokens() ) {
return;
}
// Prompt with login screen.
}
}