Api call in php with credentials - php

I'm using the cURL setup on this page to make my API calls in php.
The function call goes as follows: callAPI($method, $url, $data). I've made it work with a ('GET', 'URL', false) API call so the code does work.
Now I want to make a call to a different api. The data inputs I need to give are these:
Array
(
[Credentials] => Credentials Object
(
[Account] => my_account_name
[Password] => my_password
)
)
So this will need to be my $data object I believe?
I'm new to php so I don't know how I should setup my code to make this work with these data inputs.
Can somebody please help me how I should make these inputs in my API call?
Thanks in advance!

Related

Shopify is giving error 400 [Bad Request] when using https://{shop}.myshopify.com/admin/oauth/access_token

I was developing a Shopify App. It was working fine till yesterday evening, but then I started getting the Bad Request [400] error, after the user allow access to the app for his shop.
Error is below
(https://SHOP-NAME.myshopify.com/admin/oauth/access_token) in /path/to/shopify/authentication/oauth.php on line 28
Array (
[method] => POST
[uri] => https://SHOP-NAME.myshopify.com/admin/oauth/access_token
[query] => Array ( )
[headers] => Array ( )
[payload] => Array (
[client_id] => {CLIENTID}
[client_secret] => {CLIENT_SECRET}
[code] => {CODE}
)
)
I'm doing a POST cURL Request with Content-Type:application/x-www-form-urlencode and all the request are validated to be coming from shopify.
If anyone want more information I can provide.
Thanks.
If this happening after the user authorizes the app, it could be an issue with the permanent token they have received. You could try grabbing the token that is generated and doing a POSTMAN request manually to query the API to verify the token works.
If it worked before and you didn't make any changes to the app, it could be a temporary API issue, even though I found that to be rare with my app.
The code parameter that is sent from Shopify can only be used a single time.
If you re-make the original request that sends the code parameter to your server, you should be able to make the call successfully.

WP JSON API Connect

i want to post content to wordpress from other php app. i am using rest api plugin for posting and for authentication i am using oath plugin.i just want to know how to get the access token .i am referring
https://github.com/WebDevStudios/WDS-WP-JSON-API-Connect
for the json_url in the code i use
eg(http://myproject.info/wpsingle/wp-content/plugins/my_plugin/json-rest-api/lib/wp-json.php)
ends up in error.
[errors] => Array ( [wp_json_api_connection_failed_error] => Array (
[0] => There was a problem connecting to the API URL specified. ) )
[error_data] => Array ( )
I used this for the same thing. I used basic authentication. i.e. admin panel username and password for authentication. Because I was the only person who was going to post to wordpress. And the correct URL to access end point was like below
http://domain.com/wp-json/posts?filter[s]=awesome
this is the link to how to create a post. I used Guzzle to call api like below to get a posts from particular category.
$client = new \GuzzleHttp\Client();
$response = $client->get("http://domain.com/wp-json/posts?filter[category_name]=test", array('auth' => ['username','password']));
$posts = $response->json();
But, If you are going to let other people post than you must use OAuth. Because you can not share admin panel username and password with everyone.

SAML - Getting response from the identity provider

I am trying to implement SAML authentication system using onelogin.com, I am using this php library https://github.com/simplesamlphp/saml2 with below code
// Set up an AuthnRequest
$request = new SAML2_AuthnRequest();
// $request->setId(SAML2_Utils::generateId());
$request->setIssuer('http://localhost:8888/yii2/dw/advanced/frontend/web/index.php?r=site/auth');
$request->setDestination('https://app.onelogin.com/trust/saml2/http-post/sso/418578');
// Send it off using the HTTP-Redirect binding
$binding = new SAML2_HTTPRedirect();
$binding->send($request);
Above code is successfully authenticating me and posting back me to my success page, but I don't know how to get user information from posted data.
I am trying below code to get the user data
$response = new \SAML2_Response();
print_r($response);
It is giving below data
SAML2_Response Object
(
[assertions:SAML2_Response:private] => Array
(
)
[inResponseTo:SAML2_StatusResponse:private] =>
[status:SAML2_StatusResponse:private] => Array
(
[Code] => urn:oasis:names:tc:SAML:2.0:status:Success
[SubCode] =>
[Message] =>
)
[extensions:protected] =>
[tagName:SAML2_Message:private] => Response
[id:SAML2_Message:private] => _afe4d7fd7add270de7d334231e2eec68d1492363130
[issueInstant:SAML2_Message:private] => 14340322405
[destination:SAML2_Message:private] =>
[consent:SAML2_Message:private] => urn:oasis:names:tc:SAML:2.0:consent:unspecified
[issuer:SAML2_Message:private] =>
[relayState:SAML2_Message:private] =>
[document:protected] =>
[signatureKey:SAML2_Message:private] =>
[messageContainedSignatureUponConstruction:protected] =>
[certificates:SAML2_Message:private] => Array
(
)
[validators:SAML2_Message:private] => Array
(
)
)
From above output I am not able to get user information, Please help.
Your code:
$response = new \SAML2_Response();
actually creates a new SAML 2.0 Response object instead of parsing the one that is posted back from the IDP. This call should be used by an IDP that wants to create a SAML response. You should be looking to execute something like the following code on the Assertion Consumer (ACS) URL:
$b = SAML2_Binding::getCurrentBinding();
$response = $b->receive();
but I would very strongly advise you to use simpleSAMLphp itself (or another 3rd party SAML implementation) for integration SAML in to your PHP application since it deals with all complex and security sensitive SAML processing.
The SAML 2.0 library is only meant for developers who want to use SAML for other purposes than Web SSO or that want to rebuild a SAML implementation because simpleSAMLphp does not suit them. Assuming you have no requirements that simpleSAMLphp can't meet, you're far better off (and secure) using that. Moreover, if you'd have an extension requirement, I would create a pull request for simpleSAMLphp instead of redoing that project from scratch.
#HansZ is right. Be careful when using directly the SAML core of simpleSAMLphp instead the whole framework.
I also wanted to suggest an alternative, since you want to connect your application with onelogin.com, why not use the OneLogin's PHP SAML Toolkit? https://github.com/onelogin/php-saml

MailGun API doesn't output JSON

I am trying to test sending emails using the Mailgun api. I am using PHP to interface with the api. Following is the code that I have tried (from here).
# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;
# Instantiate the client.
$mgClient = new Mailgun('key-3ax6xnjp29jd6fds4gc373sgvjxteol0');
$domain = "samples.mailgun.org";
# Make the call to the client.
$result = $mgClient->sendMessage("$domain",
array('from' => 'Excited User <me#samples.mailgun.org>',
'to' => 'Baz <baz#example.com>',
'subject' => 'Hello',
'text' => 'Testing some Mailgun awesomness!'));
var_dump($result);
Now when I try the API, I get a response similar to the following:
stdClass Object ( [http_response_body] => stdClass Object ( [message] => Queued.
Thank you. [id] => <12345678901234.1234.12345#samples.mailgun.org> )
[http_response_code] => 200 )
How do I assign this output to an array or convert this to simple JSON using PHP? Is there some in-built PHP function which would format the above output to simple JSON or do I need to do something else. I have beginner level PHP skills.
Any help would be very appreciated. Thanks!
P.S.: The mailgun api key used above is from the MailGun API documentation.
UPDATE: Thanks guys. I got it working.
$darr=json_encode($result);
$data= json_decode($darr,true);
# Prints out the individual elements of the array
echo $data["http_response_body"]["message"]."<br>";
echo $data["http_response_body"]["id"]."<br>";
echo $data["http_response_code"];
You could try the php built-in function json_encode().
http://us3.php.net/json_encode

Evernote Integration With PHP

I have successfully done with the authentication of Evernote with PHP.
And I have got this response.
Array ( [oauth_token] => S=s1:U=6316e:E=144fcfdfdb9:C=13da54cd1ba:P=185:A=maheshchari-2599:V=2:H=6da806fe92b9289cf0334f04e2afdc55 [oauth_token_secret] => [edam_shard] => s1 [edam_userId] => 405870 [edam_expires] => 1395813907897 [edam_noteStoreUrl] => https://sandbox.evernote.com/shard/s1/notestore [edam_webApiUrlPrefix] => https://sandbox.evernote.com/shard/s1/ )
Now, I want the list of notebooks of the user which has been authenticated with evernote.
I have done a lot of research online but I couldnt find any thing which helps, I have came to know that guid is necessary to get the list of notebooks.
From where I can find that? And how can i access the notestore and userstore?
How can i call the functions of notestore and userstore to fetch the data of user's account and user's notes in php?
Thanks in Advance.
Using the Evernote SDK for PHP, you can list notebooks like the way below:
$client = new Client(array('token' => $authToken));
$noteStore = $client->getNoteStore();
$notebooks = $noteStore->listNotebooks();
All the API references can be found here.
Also, you shouldn't make your token public. Please make sure your token string you put can't be used any more. If you need more help on this, you can get supports from Evernote developer support.
https://github.com/evernote/evernote-sdk-php
go to this link and download this zip then go to sample folder then go to client folder and run EDAMTest.php page.
and add authtoken.

Categories