PHP/JS SDK LOGIN WITH Google - I have to use this file in AJAX REQUEST BELOW:

56 views
Skip to first unread message

Leonidas Savvides

unread,
Oct 6, 2015, 3:31:48 AM10/6/15
to immobilienscout24-development
I used composer and installed localhost >>>  //  TRYING USE OF GOOGLE WEB APP LOGIN API - JS SDK & VERIFY ON THE SERVER PHP SDK
https://developers.google.com/api-client-library/php/start/installation

I have to use this file in AJAX REQUEST BELOW:
\g_PHP_SDK\vendor\google\apiclient\src\Google\Client.php
WHERE INSERT THE CODE set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');//????


Then, send the ID token to your server with an HTTPS POST request:

var xhr = new XMLHttpRequest();
xhr
.open('POST', 'https://yourbackend.example.com/g_PHP_SDK/vendor/google/apiclient/src/Google/Client.php');
xhr
.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr
.onload = function() {
  console
.log('Signed in as: ' + xhr.responseText);
};
xhr
.send('idtoken=' + id_token);


Setting include_path dynamically in your code

Alternatively, you can set the same ini directive dynamically in your code.

set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src');

Leonidas Savvides

unread,
Oct 6, 2015, 4:08:00 AM10/6/15
to immobilienscout24-development
Or I must have sthg like: // in target of this file xhr.open('POST', 'https://yourbackend.example.com/g_PHP_SDK/yyy.php');
if yes, what lib PHP of google import and how? and where (in what lib file - installed via Composer) add my keys?
getUserFromToken($_POST["idtoken"]);
function getUserFromToken($token) { // https://developers.google.com/api-client-library/php/guide/aaa_idtoken
  $ticket
= $client->verifyIdToken($token);
 
if ($ticket) {
    $data
= $ticket->getAttributes();
   
return $data['payload']['sub']; // user ID
 
}
 
return false
}
Message has been deleted

Lse

unread,
Oct 6, 2015, 9:47:59 AM10/6/15
to immobilienscout24-development
getUserFromToken($_POST["idtoken"]);  // after many tries this must be the problem - I use SDK JS and want verify key on the server(PHP) but getting nothing from this(last post) function run - may called wrong... how call this?

Lse

unread,
Oct 6, 2015, 9:54:36 AM10/6/15
to immobilienscout24-development
 tried localhost is like this never called: getUserFromToken($_POST["idtoken"]);... any hint?

Rob Bors

unread,
Oct 6, 2015, 10:09:38 AM10/6/15
to immobilienscout24-development
Hi Lse,
I haven't read all of your mails, but what I can tell you is that google only supports oAuth 2.0 and we use oAuth 1.0a. So you can't use that SDK. Please use our PHP-SDK https://github.com/ImmobilienScout24/restapi-php-sdk  instead. If you need to work with JavaScript, there are lots of oauth1.0a libraries available, here:  http://oauth.net/code

Lse

unread,
Oct 7, 2015, 8:15:06 AM10/7/15
to immobilienscout24-development
Basically PHP SDK Login OAuth is required for more secure Logins(only) rather JS SDK so recommended the Ajax request from JS sdk?
I think problem was using: return , rather: echo , in ajax/PHP... that is Nothing returned...
Reply all
Reply to author
Forward
0 new messages