source/php/OAuth/OAuthRequests.php
public function requestOAuth()
    {
        if ((!isset($_POST['client'])) || (!isset($_POST['secret'])) || (empty($_POST['client'])) || (empty($_POST['secret']))) {
            wp_send_json_error(__('Request credentials is missing', 'event-integration'));
        }

        // Skip SSL verification while DEV_MODE is true
        $options = array(
            'ssl' => array(
                'verify_peer' => defined('DEV_MODE') && DEV_MODE === true ? false : true,
                'verify_peer_name' => defined('DEV_MODE') && DEV_MODE === true ? false : true
            )
        );

        $consumerKey = $_POST['client'];
        $consumerSecret = $_POST['secret'];
        // Get API base url
        $apiOauthUrl = get_field('event_api_oauth_url', 'option');
        if (! $apiOauthUrl) {
            wp_send_json_error(__('You must enter OAuth1 endpoint url found under Event settings to proceed.', 'event-integration'));
        }
        $url                  = rtrim($apiOauthUrl, '/');
        $requestTokenUrl      = $url . "/request";
        $authorizeUrl         = $url . "/authorize";
        $oauthTimestamp       = time();
        $nonce                = md5(mt_rand());
        $oauthSignatureMethod = "HMAC-SHA1";
        $oauthVersion         = "1.0";
        // Create OAuth signature base string
        $sigBase = "GET&" . rawurlencode($requestTokenUrl) . "&"
            . rawurlencode("oauth_consumer_key=" . rawurlencode($consumerKey)
            . "&oauth_nonce=" . rawurlencode($nonce)
            . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
            . "&oauth_timestamp=" . $oauthTimestamp
            . "&oauth_version=" . $oauthVersion);
        // URL encode consumer secret key to bo used in signature
        $sigKey = rawurlencode($consumerSecret) . "&";
        // Signature = HMAC-SHA1 hash base string + key
        $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));
        // Create OAuth request url with our signature
        $requestUrl = $requestTokenUrl . "?"
            . "oauth_consumer_key=" . rawurlencode($consumerKey)
            . "&oauth_nonce=" . rawurlencode($nonce)
            . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
            . "&oauth_timestamp=" . rawurlencode($oauthTimestamp)
            . "&oauth_version=" . rawurlencode($oauthVersion)
            . "&oauth_signature=" . rawurlencode($oauthSig);
        // Get results from request
        $response = file_get_contents($requestUrl, false, stream_context_create($options));

        // Return error message if request failed
        if ($response === false) {
            wp_send_json_error(__('The credentials you supplied were not correct', 'event-integration'));
        }

        parse_str(trim($response), $values);

        // Save client keys and temporary tokens to db
        update_option('_event_client', $consumerKey);
        update_option('_event_secret', $consumerSecret);
        update_option('_temp_request_token', $values["oauth_token"]);
        update_option('_temp_request_token_secret', $values["oauth_token_secret"]);

        $verificationUrl = $authorizeUrl . "?oauth_token=" . $values["oauth_token"];

        // Return JSON response with verification url
        $data = array("message" => __('Request succeeded!', 'event-integration'), "url" => '<a href="' . $verificationUrl . '" target="_blank">' . __('Click here to authorize this client and get verification token', 'event-integration') . '</a>');
        wp_send_json_success($data);
    }
public function requestOAuth()
    {
        if ((!isset($_POST['client'])) || (!isset($_POST['secret'])) || (empty($_POST['client'])) || (empty($_POST['secret']))) {
            wp_send_json_error(__('Request credentials is missing', 'event-integration'));
        }

        // Skip SSL verification while DEV_MODE is true
        $options = array(
            'ssl' => array(
                'verify_peer' => defined('DEV_MODE') && DEV_MODE === true ? false : true,
                'verify_peer_name' => defined('DEV_MODE') && DEV_MODE === true ? false : true
            )
        );

        $consumerKey = $_POST['client'];
        $consumerSecret = $_POST['secret'];
        // Get API base url
        $apiOauthUrl = get_field('event_api_oauth_url', 'option');
        if (! $apiOauthUrl) {
            wp_send_json_error(__('You must enter OAuth1 endpoint url found under Event settings to proceed.', 'event-integration'));
        }
        $url                  = rtrim($apiOauthUrl, '/');
        $requestTokenUrl      = $url . "/request";
        $authorizeUrl         = $url . "/authorize";
        $oauthTimestamp       = time();
        $nonce                = md5(mt_rand());
        $oauthSignatureMethod = "HMAC-SHA1";
        $oauthVersion         = "1.0";
        // Create OAuth signature base string
        $sigBase = "GET&" . rawurlencode($requestTokenUrl) . "&"
            . rawurlencode("oauth_consumer_key=" . rawurlencode($consumerKey)
            . "&oauth_nonce=" . rawurlencode($nonce)
            . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
            . "&oauth_timestamp=" . $oauthTimestamp
            . "&oauth_version=" . $oauthVersion);
        // URL encode consumer secret key to bo used in signature
        $sigKey = rawurlencode($consumerSecret) . "&";
        // Signature = HMAC-SHA1 hash base string + key
        $oauthSig = base64_encode(hash_hmac("sha1", $sigBase, $sigKey, true));
        // Create OAuth request url with our signature
        $requestUrl = $requestTokenUrl . "?"
            . "oauth_consumer_key=" . rawurlencode($consumerKey)
            . "&oauth_nonce=" . rawurlencode($nonce)
            . "&oauth_signature_method=" . rawurlencode($oauthSignatureMethod)
            . "&oauth_timestamp=" . rawurlencode($oauthTimestamp)
            . "&oauth_version=" . rawurlencode($oauthVersion)
            . "&oauth_signature=" . rawurlencode($oauthSig);
        // Get results from request
        $response = file_get_contents($requestUrl, false, stream_context_create($options));

        // Return error message if request failed
        if ($response === false) {
            wp_send_json_error(__('The credentials you supplied were not correct', 'event-integration'));
        }

        parse_str(trim($response), $values);

        // Save client keys and temporary tokens to db
        update_option('_event_client', $consumerKey);
        update_option('_event_secret', $consumerSecret);
        update_option('_temp_request_token', $values["oauth_token"]);
        update_option('_temp_request_token_secret', $values["oauth_token_secret"]);

        $verificationUrl = $authorizeUrl . "?oauth_token=" . $values["oauth_token"];

        // Return JSON response with verification url
        $data = array("message" => __('Request succeeded!', 'event-integration'), "url" => '<a href="' . $verificationUrl . '" target="_blank">' . __('Click here to authorize this client and get verification token', 'event-integration') . '</a>');
        wp_send_json_success($data);
    }
OAuth1 verification step 1: Send a request to API with client keys. Return verification URL if succeeded.
OAuth1 verification step 2 (handled on the OAuth1 server): User authorizes the client from the verification URL and will be given a verifier key,
that will be used in step 3
@return void