Google PHP API Client fetchAccessTokenWithAuthCode() not working - google-oauth

Environment details
OS: Ubuntu 20
PHP version: 7.3.33
Package name and version: api-client v2.12.1 / 2.10.0 / 2.9.2
Steps to reproduce
After redirection to callback url with auth code from google, I am trying to fetch the access token using auth code by calling fetchAccessTokenWithAuthCode('auth code') but it gets stuck and nothing comes after. It basically returns a request timeout as no response is returned from Google even after 05 minutes.
Code example
$client = new Google\Client;
$client->setApplicationName("CM");
$client->setScopes(Google_Service_Sheets::SPREADSHEETS_READONLY);
$client->setAuthConfig('client_secret.json');
if ($_GET['code']) {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
$client->setAccessToken($token);
// Check to see if there was an error.
if (array_key_exists('error', $token)) {
throw new Exception(join(', ', $token));
}
}
Thanks!

Seems the issue was my ISP blocking the Google API URL. It stands resolved now.

Related

MobileFirst Obtain Access token and Login give no response after setting WL.App.setServerURL

As per my requirement, I am using WL.APP.setServerURL before every login request WLAuthorizationManager.loginof mobilefirst.
When I do first an valid/Invalid login attempt it works fine. As on next attempt I do WL.App.setServerURL, and then WLAuthorizationManager.login (login request) OR WLAuthorizationManager.obtainAccessToken (obtain access token request) don't respond anything. No success and no fail. Although non-secure adapter method works fine.
If I do WL.APP.setServerURL only once on application startup, everything works fine but in between call cause application failure.
let url = ... //fetcht url from adapter call
WL.App.setServerUrl(url, function (sucess) {
WLAuthorizationManager.login(securityCheckName, loginParam).then((data) => {
.... //After login code
}, (response) => {
//Login fail code
});
}, function (error) {
});
Flow :-
I call above code on click of login button.I call a method to get server url from adapter first then I set that url as server url.
When I do an invalid attempt of login it works find for first time, and on next call MFP login, it doesn't respond. Not success nor fail in application.
I am getting error in native logs android.
Android Error logs :-
E/SecurityCheckChallengeHandler(30199): SecurityCheckChallengeHandler.submitChallengeAnswer in SecurityCheckChallengeHandler.java:51 :: submitAnswer has been called for unknown request
.
MobileFirst server version :- 8.0.0.00-20170911-123510
MobileFirst Cordova(plugin) version :- 8.0.2017102403
The WL.App.setServerUrl API is meant to be used sparingly whenever the app needs to connect to a server other than the one defined in mfpclient.properties. If you want to keep the server URL constant, you should just put it up in the mfpclient.properties.
Having said that, the behaviour you mention is not expected - can you update your question with a code snippet of your app performing login & setServerUrl

I am using vue-resource with vue cli webpack i have 'Access-Control-Allow-Origin' issue

mounted(){
this.$http.get('http:anotherurl.com/api/data.xml')
.then(function (response) {
console.log(response);
});
}
i get this console error :
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
i test vue-resource with reddit and it worked fine but with this url gives the problem . please help .
The people who set up anotherurl.com have configured it to not allow requests via JavaScript from sites other than their own. This is a feature of HTTP / CORS.
For further reading, the Mozilla documentation explains a little more about what is going on:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Access-Control-Allow-Origin
If you are using chrome you can get an extension to ignore xframe-headers. don't know how to solve it in production though
I would say that as vue-resource is deprecated from 2.0 v you should look at newer API like this one here - https://github.com/mzabriskie/axios
Axios is powerful-promise based HTTP client for the browser and node.js

"hostname doesn't match" when using requests in PythonAnywhere

EDIT: I fixed the problem, see links in the answer.
I'm using the XMLHttpRequest AJAX API to send data from different websites to our server in PythonAnywhere.
Something odd happens: depending on the website, either we send successfully or we get this error
POST https://canecto.pythonanywhere.com/api/ 500 (Internal Server Error)
even though the same code is loaded.
I tried to manually open the request and send data via JavaScript console in Chrome but nothing changes.
Here is how the snippet looks like:
var url = "https://canecto.pythonanywhere.com/api/";
var xmlHttpPost = new XMLHttpRequest();
xmlHttpPost.open("POST", url, true);
xmlHttpPost.setRequestHeader("Content-type", "application/json");
var postData = {
page_url: window.location.href,
time_on_page: activeTime,
cookie: cookie,
/* some variables */
};
xmlHttpPost.onreadystatechange = function() {
if (xmlHttpPost.readyState == 4 && XMLHttpRequest.DONE) {
console.log('');
}
};
/* send data */
xmlHttpPost.send(JSON.stringify(postData));
I read here that the problem should not be the client-side JavaScript.
If I inspect on the server side, for the line requests.get(page_url, headers=HEADER, timeout=10)(where I try to access the page) I get this log:
I read on the Python request library that it may be something related to the SSL verification, but I have very little clue about it. I tried to check other similar questions but I have not found the answer.
Has anybody experienced anything similar and successfully solved it?
To whom it still uses Python < 2.7.9: this answer worked for me. SNI is not supported in Python 2, that means you should follow such answer and these requirements to make requests work with SSL certificate verification.

Google Adwords API error - The OAuth client was deleted

I'm new to the Google Adwords API and so far have managed to get the refresh token by running 'GetRefreshToken.php' via the command line.
/usr/bin/env php mypath/adwords/examples/AdWords/Auth/GetRefreshToken.php
However, when trying out one of the recommended examples - 'GetCampaigns.php', I get the following error -
An error has occurred: {
"error" : "deleted_client",
"error_description" : "The OAuth client was deleted."
}
Has anyone else had this problem?
Thanks
I was having a similar problem with the Calendar api. The way to fixed was to delete the files in the .credentials folder in my home directory. Then when i used the new credentials and it worked fine!.
In my case the ./credentials folder was in the following path:
/Users/myusername/.credentials
I'm using OS X Yosemite 10.10.5

cPanel, Laravel TokenMismatchException with Cookies not being set

I recently moved my laravel application to a production server rather than just developing locally. However since doing so I have been unable to login to the site as I keep running into Illuminate \ Session \ TokenMismatchException.
I never had the issue on the local server, just when I ported it over the production server.
I have looked into the tokens and they never match at all. My code is as follows:
Route::filter('csrf', function()
{
// Check ajax requests for token validity via the header.
// app.js has the code to grab form tokens and put it in
// a header, well validate it here if its a post AJAX
if (Request::ajax() && Request::getMethod() == 'POST')
{
if (Session::getToken() != Request::header('X-CSRF-Token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
} else {
if (Request::getMethod() == 'POST' && Session::token() != Input::get('_token'))
{
throw new Illuminate\Session\TokenMismatchException;
}
}
});
The error occurs when I am trying to compare Session::token() to Input::get('_token)
So my question is, is there something blatantly obvious that I am missing in regards to the difference between tokens on a local server to that of a production server?
Any help on this would be greatly appreciated!
~Additional Information~
From the other sources I've found there are similar issues where the session isn't persisting. I'm already on Laravel 4.1 so the lifetime and expire_on_close are already set to the default of 120 and false. I have also tried changing the session driver to file/database/cookie all with the same outcome.
~Another Update~
Ok, somewhere a bit closer, looking into browser resources, on my local server a cookie is set laravel_session, however on my web server this is not appearing at all. So think this is related it.
I couldn't solve this. In the end though I found that is was related to the use of cPanel, as soon as I used another hosting provider without cPanel the issue has never occured.