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

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.

Related

I'm having trouble authenticating to Office 365 IMAP using Chilkat OAuth2. "Authenticate failed"

Good Afternoon,
I have an application and we're trying to connect to out IMAP server using Chilkat (PHP Extension), via the Client Credential Flow method, since it's supposed to be a server-to-server connection, without user interaction.
We're using the Microsoft Graph example as a base-code (https://www.example-code.com/phpExt/microsoft_graph_client_credentials.asp), but we're using the scope (https://ps.outlook.com/.default), link and API permissions as described in the Microsoft Documentation (https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth#use-client-credentials-grant-flow-to-authenticate-imap-and-pop-connections).
I'm able to generate the Access Token, but when we try to connect to an authorized mailbox, we are greeted with the following error message:
ChilkatLog:
Login:
DllDate: Jan 31 2021
ChilkatVersion: 9.5.0.85
UnlockPrefix: OUR_UNLOCK_CODE_HERE
Architecture: Little Endian; 64-bit
Language: Linux PHP
VerboseLogging: 0
loginX:
greeting: * OK The Microsoft Exchange IMAP4 service is ready. [SOME_CK_GENERATED_CODE_HERE]
authenticateXOAuth2:
xoauth2Imap:
ConnectionType: SSL/TLS
--xoauth2Imap
isOK:
serverResponse: aaab NO AUTHENTICATE failed.
--isOK
--authenticateXOAuth2
--loginX
Failed.
--Login
--ChilkatLog
I have tried using the token generated via postman, I've tried every single API permission that I found out on the Microsoft Documentation, and I have tried many different chilkat implementations on my server... All to no avail.
All I need is some way to connect to my IMAP folders, since we are currently using basic Auth (and basic Auth for IMAP will die at the end of the year).
I'm not sure what the problem is, since we gave our test email IMAP parmissions and followed to the letter the microsoft documentation. I'm a little lost on what could be causing the error, the API permissions, the mailbox permissions or our Chilkat PHP implementation. Can you guys help me find out what is going on, please? Thanks!
I feel your pain because I haven't been able to get client_credentials working with Office365 either.
It's a common use case, and you'd think Microsoft would make it easy.
My only suggestion (for now) is to get the very first OAuth2 access token using authorization flow (i.e. interactively with a browser), and then refresh non-interactively as needed from that point forward.
The blog post is a good starting point for using Chilkat with Office365 OAuth2:
https://cknotes.com/office365-modern-authentication-for-imap-pop3-and-smtp/

401 while creating customer in quickbooks using php api

I keep getting 401 in spite of using the test keys from the playground app, can someone help on how to resolve this, code works fine on a dev server, as soon as code moved to qa server i created a new QuickBooks account and a new app and now i keep getting a 401
Just moving code from one server to another is a guaranteed way to break anything OAuth related.
You would need to at least:
Move the code
Change the OAuth URLs in Intuit's control panel to point to the new server
Change the OAuth URLs in your code
Clear any stored OAuth access tokens from your database (if you moved the data in the database to the new server as well)
Reconnect to QuickBooks, via the [Connect to QuickBooks] button
Additional notes:
Why are you using test keys from Intuit's playground app? Create your own app, and use your own keys.
If you created a new app, you'll also need to swap our your OAuth consumer key, OAuth consumer secret, and App token in your code.
Be aware that if your app is in DEVELOPMENT mode, then you can only connect to DEVELOPMENT QuickBooks accounts. If you created a LIVE QuickBooks account, you can only connect to it with PRODUCTION/LIVE app credentials (e.g. you need to PUBLISH your app).
Since you didn't post:
Your code
Screenshots of the credentials from Intuit's control panel (assuming they are dev/sandbox and thus safe to post)
Any of the HTTP requests/responses you're sending/receiving
We won't be able to really help you much further.

OAuth authentication in API to connect to ETSY

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.

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 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