Trouble with authentication in vk.com with zend_oauth
Message:
Error in HTTP request: Unable to enable crypto on TCP connection oauth.vk.com: make sure the "sslcafile" or "sslcapath" option are properly set for the environment.
Help me please
You need to use curl as adapter and turn off ssl certificate checks:
$adapter = new \Zend\Http\Client\Adapter\Curl();
$adapter = $adapter->setCurlOption(CURLOPT_SSL_VERIFYHOST, false);
$adapter = $adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
$config = array(
'siteUrl' => 'https://url',
'consumerKey' => 'login',
'consumerSecret' => 'pass'
);
$consumer = new \ZendOAuth\Consumer($config);
/** #var \Zend\Http\Client $httpClient */
$httpClient = $consumer->getHttpClient();
$httpClient->setAdapter($adapter);
Related
I want to add contact in mautic via an API. Below I have the code, but it's not adding the contact in mautic.
I have installed mautic in localhost. Studied the API form in the mautic documentation and tried to do it for at least 2 days, but I am not getting any results on it.
<?php
// Bootup the Composer autoloader
include __DIR__ . '/vendor/autoload.php';
use Mautic\Auth\ApiAuth;
session_start();
$publicKey = '';
$secretKey = '';
$callback = '';
// ApiAuth->newAuth() will accept an array of Auth settings
$settings = array(
'baseUrl' => 'http://localhost/mautic', // Base URL of the Mautic instance
'version' => 'OAuth2', // Version of the OAuth can be OAuth2 or OAuth1a. OAuth2 is the default value.
'clientKey' => '1_1w6nrty8k9og0kow48w8w4kww8wco0wcgswoow80ogkoo0gsks', // Client/Consumer key from Mautic
'clientSecret' => 'id6dow060fswcswgsgswgo4c88cw0kck4k4cc0wkg4gows08c', // Client/Consumer secret key from Mautic
'callback' => 'http://localhost/mtest/process.php' // Redirect URI/Callback URI for this script
);
/*
// If you already have the access token, et al, pass them in as well to prevent the need for reauthorization
$settings['accessToken'] = $accessToken;
$settings['accessTokenSecret'] = $accessTokenSecret; //for OAuth1.0a
$settings['accessTokenExpires'] = $accessTokenExpires; //UNIX timestamp
$settings['refreshToken'] = $refreshToken;
*/
// Initiate the auth object
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);
/*
if( $auth->getAccessTokenData() != null ) {
$accessTokenData = $auth->getAccessTokenData();
$settings['accessToken'] = $accessTokenData['access_token'];
$settings['accessTokenSecret'] = 'id6dow060fswcswgsgswgo4c88cw0kck4k4cc0wkg4gows08c'; //for OAuth1.0a
$settings['accessTokenExpires'] = $accessTokenData['expires']; //UNIX timestamp
$settings['refreshToken'] = $accessTokenData['refresh_token'];
}*/
// Initiate process for obtaining an access token; this will redirect the user to the $authorizationUrl and/or
// set the access_tokens when the user is redirected back after granting authorization
// If the access token is expired, and a refresh token is set above, then a new access token will be requested
try {
if ($auth->validateAccessToken()) {
// Obtain the access token returned; call accessTokenUpdated() to catch if the token was updated via a
// refresh token
// $accessTokenData will have the following keys:
// For OAuth1.0a: access_token, access_token_secret, expires
// For OAuth2: access_token, expires, token_type, refresh_token
if ($auth->accessTokenUpdated()) {
$accessTokenData = $auth->getAccessTokenData();
echo "<pre>";
print_r($accessTokenData);
echo "</pre>";
//store access token data however you want
}
}
} catch (Exception $e) {
// Do Error handling
}
use Mautic\MauticApi;
//use Mautic\Auth\ApiAuth;
// ...
$initAuth = new ApiAuth();
$auth = $initAuth->newAuth($settings);
$apiUrl = "http://localhost/mautic/api";
$api = new MauticApi();
$contactApi = $api->newApi("contacts", $auth, $apiUrl);
$data = array(
'firstname' => 'Jim',
'lastname' => 'Contact',
'email' => 'jim#his-site.com',
'ipAddress' => $_SERVER['REMOTE_ADDR']
);
$contact = $contactApi->create($data);
echo "<br/>contact created";
Any help will be appreciated.
use Curl\Curl;
$curl = new Curl();
$un = 'mayank';
$pw = 'mayank';
$hash = base64_encode($un.':'.$pw);
$curl->setHeader('Authorization','Basic '.$hash);
$res = $curl->post(
'http://mautic.local/api/contacts/new',
[
'firstname'=>'fn',
'lastname'=>'ln',
'email'=>'t1#test.com'
]
);
var_dump($res);
This is something very simple i tried and it worked for me, please try cleaning cache and enable logging, unless you provide us some error it's hard to point you in right direction. Please check for logs in app/logs directory as well as in /var/logs/apache2 directory.
In my experience sometimes after activating the API in the settings the API only starts working after clearing the cache.
Make sure you have activated the API in the settings
Clear the cache:
cd /path/to/mautic
rm -rf app/cache/*
Then try again
If this didn't work, try to use the BasicAuth example (You have to enable this I the settings again and add a new User to set the credentials)
I suspect that the OAuth flow might be disturbed by the local settings / SSL configuration.
these steps may be useful:
make sure API is enabled(yes I know it's might be obvious but still);
check the logs;
check the response body;
try to send it as simple json via Postman
it may be one of the following problems:
Cache;
You are not sending the key:value; of the required custom field;
you are mistaken with authentication;
Good luck :)
I am receiving this error immediately after installing my app in my dev store when attempting to exchange the temporary access code for a permanent token.
Oauth error invalid_request: Could not find Shopify API application with api_key
I'm using below code
$client = new Client();
$response = $client->request(
'POST',
"https://{$store}/admin/oauth/access_token",
[
'form_params' => [
'client_id' => $api_key,
'client_secret' => $secret_key,
'code' => $query['code']
]
]
);
$data = json_decode($response->getBody()->getContents(), true);
$access_token = $data['access_token'];
Any help is much appreciated. Thanks!
I have set up a Zend SOAP client and server:
See partial code below. In the client I set a username and password in the headers.
But I cannot find any information on how to extract this in the server so that I can authenticate the incoming message, ideally through the Zend_Auth stuff I already use for the rest of the system
Cient:
$username = "user";
$password = "pass";
// initialize SOAP client
$options = array(
'location' => 'http://dev.local/api/soap/index',
'uri' => 'http://dev.local/api/soap/index',
'soap_version' => SOAP_1_2,
'login' => $username,
'password' => $password
);
try {
$client = new Zend_Soap_Client(null, $options);
Server:
$options = array('uri' => 'http://dev.local/api/soap');
$server = new Zend\Soap\Server(null, $options);
$manager = new Manager_Api_Soap();
$server->setClass($manager);
You're able to get header values of variables like this within zend:
$this->getRequest()->getHeader('login')
For further details have a look at a prior answer from me regarding Zend and REST:
Zend Framework 1.12 plugin for checking "Authorization" header
I am trying to send a mail using YiiMailer Extension, when I used Port 465 getting error "fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host" and when I used port 587 its fails to send a mail.
Code:
In controller:
$mail = new YiiMailer();
$mail->setData(array('message' => 'Message to send', 'name' => 'John Doe', 'description' => 'Contact form', 'mail' => $mail));
$mail->setFrom('abc#gmail.com', 'John Doe');
$mail->setTo($_POST['UserLogin']['email']);
$mail->setSubject('Reser Password');
$mail->setBody('Simple message');
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->Username = "*******#gmail.com";
$mail->Password = "********";
if ($mail->send()) {
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
Yii::log("Mail sent");
} else {
Yii::app()->user->setFlash('error','Error while sending email: '.$mail->getError());
Yii::log("Mail Error");
}
}
In main.php
'import'=>array(
'application.models.*',
'application.components.*',
'ext.YiiMailer.YiiMailer',
),
Please help me to come out of this problem and I tried other extension too like Emailer, PHPMailer but there i got some SMTP error "smtp unable to connect to the remote server"
Thanks in advance
I am guessing you do not have php_openssl enabled in your server's php.ini. Check phpinfo() to make sure you have it enabled.
Also you may need to add the lines
$mail->SMTPSecure='ssl';
$mail->Mailer='smtps';
This works for me!
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->SMTPSecure= 'tls';
$mail->Username = "*******#gmail.com";
$mail->Password = "********";
I am using Fiddler to get all traffic on an Apache server. The problem is that Fiddler captures every thing except HTTP Requests from Apache sent with Zend_HTTP_Client. What should I do?
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
'proxy_host' => '127.0.0.1',
'proxy_port' => 8888,
'timeout' => 60,
'useragent' => 'Test',
'keepalive' => true,
'sslusecontext' => true
);
$client = new Zend_Http_Client('http://www.site.com/', $config);