OAuth authentication in API to connect to ETSY - php

I am trying to create an API to connect to ETSY and obtain orders information. They require authentication with OAuth.
I am looking for a script that can do the OAuth step relying on an external library, and not on a pre-installed server package, as ipage.com (my current host) does not have the OAuth package installed.

Not sure where you got that code from exactly, but the correct class you want to instantiate is \OAuth\OAuth1\Service\Etsy. Each service in the library has its own class.
You don't have to look at the individual implementations for connecting users with your app. We already have abstracted that part for you. The easiest way to get you started with the Etsy service is to copy the example.
You can add your key and secret here.
Once the user has approved your app you can start making requests to the service. An example of this can be found here.
From that point on you can simply make requests by doing $etsyService->request('/whatever/you/want/to/get') by choosing the correct path from http://www.etsy.com/developers/documentation.

Probably because etsy did not return a login_url
First, try print_r($req_token) - see if that provides anything useful (like an error message)
Failing that, if $req_token is false, you may want to see if your SSL libraries are up to par. Try a phpinfo(); and check the PHP error log to see if either (1) SSL is not supported for your PHP install or (2) there is an error with the SSL connection.

Related

Connection refused for URI https://www.googleapis.com/oauth2/v4/token

I am new to GoogleAPIs and Laravel, I run a PHP web application on Laravel 8 in a virtual Linux environment. Socialite and Drive API was working fine and out of sudden it doesn't work anymore and always return connection refused error after long period of loading as follows:
GuzzleHttp\Exception\ConnectException
Connection refused for URI https://www.googleapis.com/oauth2/v4/token
I had tried to create a new credential with new refresh token and checked all the network settings, and always clear config cache and restart apache for all troubleshoots I have tested, yet the error still exists.
I would appreciate it much if anyone could enlighten me on what are the aspects I shall look into it.
There are multiple issues in this question.
First and foremost, you are sending your secret to a third party. This means that they are able to do any API calls as you (using your name and quotas). Even if they claim that they won't, they can. Please remove any secret you may have and create new ones.
As for the OAuth 2.0, you seem to be using an old URL. You should probably take a look into the official documentation for:
Using OAuth 2.0 to Access Google APIs for a basic explanation.
Using OAuth 2.0 for Web Server Applications for making a web and getting permissions to get/modify a user's data (can be yourself).
Using OAuth 2.0 for Server to Server Applications for using a service account to execute as one of the users on your organization, without the need of manually giving permission.
Also notice that there are PHP libraries officially supported by Google to make your life way easier. See the Drive API's PHP Quickstart.

"No system CA bundle could be found" on Google App Engine on localhost

I'm working on an app that I'll be running in the Google App Engine (GAE) that needs to access the GDrive API. When it's running up in the cloud, I'm able to use my special domain-wide authorization so that my users are automatically authenticated and I can use the gdrive api without any problems. That works very well.
However, when testing on localhost, the domain-wide auth won't work because we localhost doesn't actually authenticate your Google Account, you're just allowed to claim to be anyone you want. So, what I'm doing is instantiating my google $client differently on localhost and in the GAE. In the GAE, I use the special domain-wide auth, on localhost then I'm using the traditional Google Client configuration with a client id, client secret, oauth token processing, etc.
I redirect to Google, I tell Google to allow access, and then Google redirects me back to localhost to finalize the oauth process. When I take the code from google and call:
$client->authenticate($authcode);
I get an SSL error about a missing CA bundle.
No system CA bundle could be found in any of the the common system
locations. PHP versions earlier than 5.6 are not properly configured
to use the system's CA bundle by default. In order to verify peer
certificates, you will need to supply the path on disk to a
certificate bundle to the 'verify' request option:
http://docs.guzzlephp.org/en/latest/clients.html#verify. If you do not
need a specific certificate bundle, then Mozilla provides a commonly
used CA bundle which can be downloaded here (provided by the
maintainer of cURL):
https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt.
Once you have a CA bundle available on disk, you can set the
'openssl.cafile' PHP ini setting to point to the path to the file,
allowing you to omit the 'verify' request option. See
http://curl.haxx.se/docs/sslcerts.html for more information.
I've downloaded the .crt file and I've also tried downloading their .pem file and I've tried configuring my php.ini in several fashions to make it use those files...
openssl.cafile="/path/to/ca-bundle.crt"
or
openssl.cafile="/path/to/cacert.pem"
or
curl.cainfo="/path/to/ca-bundle.crt"
or
curl.cainfo="/path/to/cacert.pem"
But none of them seem to work or make a difference. What am I missing?
EDIT:
Telling me to authenticate the same on production and localhost means that you don't understand what I'm asking or the reason why I need to use the client. My question is about the certificates.
I finally found a solution from this answer, please go vote up their answer.
Looking through Google and Guzzle's code you might need to specify
where the certificate bundle can be found by doing something like the
following when you setup the Google Client and before your
authenticate() call:
$client->setHttpClient(new GuzzleHttp\Client(['verify'=>'path\to\your\cert-bundle']));
This will override the default behavior and let you specify where the
bundle is.

How to access Google Play Android Developer API through backend server

I am implemented In App Billing for android.I wanted to implement subscription validity checking through my backend server. As Google Play Documentation, for making call for Google Play API,need authentication using oauth 2.0.
I followed instructions for registering project and creating credentials. But from there I have no idea how to use those credentials, I tried authentication via CURL request, but it asking permission as shown in follwing image
This permissions works fine I can exchange code and get access token, but all this done by manually, how should I implement this on backend.
I even try to use google api php library provided by Google, but It adds confusion. Also they didn't provide any example, how to use library.
Can anybody elaborate how exactly use library or pure php?
Thanks in advance.
To perform LVL and/or IAB validation on a server, do not access Google servers directly from the server. Even if all information were available, you would face integrity problems, because your app and your server will see different information due to synchronization latencies.
Instead, use your app as a proxy and validate the Google Play information on your server as described here.

How to use PHP to authenticate against a remote Microsoft Exchange 2010

As usual, this is a weird and non-negotiable request from top management.
Anyway, the story is as following:
I will build a website at location A, let say UK (Using CentOS, PHP, Apache)
There is a login form on it, and user can enter their Exchange 2010 username (email), and password to login. Where the Exchange 2010 is at location B, let say US.
So the issue in short is that how I can authenticate with a remote Exchange 2010?
There are several suggestions thrown at me but I am not even sure this can be done in the first place...
Can we leverage Exchange 2010's OWA?
Can we use ActiveSync?
Can we use EWS? (Exchange Web Services)
I am not familiar with Microsoft's related technologies, so my question in short is that is there a web service method or similar where I can do my authentication?
Best Regards
You probably mean authenticate against Active directory in which Exchange server is integrated.Then you can use LDAP:
Authenticating in PHP using LDAP through Active Directory
I would look into the adLDAP library on Source Forge. Email me and I will send you my documentation, it takes about 20 minutes to set up and all you need is MS Active Directory, you do not need LDAP. KWSoutherlandJr At yahoo dot com.
adLDAP.courceforge.net
Yes, you can use Exchange Web Service to do this, I recommend the managed API's. Download here: http://www.microsoft.com/download/en/details.aspx?id=13480 , documentation is here: http://msdn.microsoft.com/en-us/library/dd633710%28EXCHG.80%29.aspx
Here how you could do it. First off include the right namespaces:
// use the exchange library:
using System.Security.Cryptography.X509Certificates;
using Microsoft.Exchange.WebServices.Data;
Then write some code similar to this:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
// If you've got a dodgy SSL cert on your exchange box then do this:
System.Net.ServicePointManager.ServerCertificateValidationCallback =
delegate(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors)
{
return true;
};
service.Credentials = new WebCredentials(Username, Password, domain);
service.Url = new Uri(url);
// this will fail if the username+password are incorrect:
Folder.Bind(service, WellKnownFolderName.MsgFolderRoot);
You can give EWSWrapper a try - http://ewswrapper.lafiel.net/
It's a PHP wrapper for Exchange Web Services. It will give you an idea how you can authenticate with Ex Server and what can be done with EWS. Python version has a bit better authentication as it cycles through various auth methods.
Also, you can take a look # this: Access Exchange Web Services with PHP and cURL
Cheers~

How do we setup oAuth server?

I want oAuth verification process for a mobile application.For that i need to setup an oAuth server which listens to the requests and grant the access tokens.How do i set this up?I didnt found any relevant help on net.Please let me know.Also it will be good if it could be done using CakePHP
Regards
Himanshu Sharma
You would need an OAuth library for PHP that implements an OAuth service provider.
There are PECL and PEAR OAuth libraries, but my personal testimony is oauth-php as its simpler. I implemented both a server and client with it.
I cant comment on writing a service provider in Cake.
Updates based on OP's comments
Copy that directory to your PHP application to "install" it. You would need only CURL support from your host. There are no other prerequisites from the part of your host.
I did these steps to write an OAuth provider with oauth-php, do try these, google it and ask new questions when you get stuck.
read illustrated guides on how OAuth works
Studied relevant chapters from http://oauth.net/core/1.0a/ (try this order: 3,4, appendix,6 and 7 to start with)
read the example files included with the library, and see the how-tos in site's pages
hack those files and build it up your application

Categories