PHP API installation Questions

332 views
Skip to first unread message

Billiam James

unread,
Jul 31, 2011, 4:16:12 PM7/31/11
to google-iden...@googlegroups.com
I have installed the PHP GIT API Toolkit on my server.

It successfully logs users into Gmail and returns with the personal data. 

However callback page (provided in the GIT API Toolkit) is generating this error:

Fatal error: Call to a member function getAccountByEmail() on a non-object in .../git/logic/gitCallbackLogic.php on line 34

Line 34 is:
$account = gitContext::getAccountService()->getAccountByEmail($verifiedEmail)

Does this have something to do with the Config settings? Can you suggest a way to correct this?

Thanks!

Billiam James

unread,
Aug 1, 2011, 10:31:45 AM8/1/11
to google-iden...@googlegroups.com
Fixed. Problem was caused by extras spaces in the 'externalClassPaths' settings of the config file, (e.g. it was 'externalClassPaths' => 'logic, util, session, data', instead of  'externalClassPaths' => 'logic,util,session,data') so it was not loading my implementation class of the gitAccountService interface.

Vaishakh Thayyil

unread,
Aug 3, 2011, 7:20:05 AM8/3/11
to google-iden...@googlegroups.com
Hi Billiam James ,

Great to see you have already integrated Google Identity Toolkit to your Site , 
I have some doubts the current PHP code sample they have given is integrated
with OpenCart . I dont have and need to use OpenCart in my sytem , what I need
is just PHP . I have downloaded the tookit but I am bit confused with the integration,
If you have implemented it in pure PHP can you provide guidelines on integration 
or even a sample code may be helpful . 

Email vaishakh.r @gmail.com

Jinhui Du

unread,
Aug 3, 2011, 12:14:25 PM8/3/11
to google-iden...@googlegroups.com
Hi Vaishakh

The GITkit PHP client library(download link here) provides the common GITkit integration code e.g. widget AJAX handler, communication with the GITkit API server, interface the RP needs to implement and etc. It is not related to OpenCart. 
The sample OpenCart integration shows how to integrate with a real e-commerce site. There are several steps to describe what OpenCart code is changed to integrate federated login using GITkit on the sample page. The changed files can be downloaded as a package. You need to change corresponding parts on your own site.

Vaishakh Thayyil

unread,
Aug 3, 2011, 3:43:18 PM8/3/11
to google-iden...@googlegroups.com
Thanks Jinhui Du for your quick repsonse ,

I have already seen this links , what I am stuck with is to use those libraries, 

I have customized those javascript code with all the necessary URL's . 

I have set callback URL to the callback.php page in the package I have 

downloaded . I am not at all clear with the callback procedure 

 
In this line "Your server needs to call the verifyAssertion API to validate the IDP's response "

it says you have to call the verifyAssertion API to verify the response , how do I do it using the 

packages ?

The  callback.php page contains takes 2 get request $_GET['rp_input_email'] & $_GET['rp_purpose']

I tried calling callback.php page directly with rp_input_email=vaish...@gmail.com ,what is rp_purpose

for ? Is there any documenation or guide regarding what php files are used for what ? Any one sample 

php that is integrated with the UI would be useful to understand the flow . 

It would also be great of Billiam James if he could blog or provide sample code tips

on how he had integrated GIT .

Thanks ,

Vaishakh  

Jinhui Du

unread,
Aug 3, 2011, 4:38:24 PM8/3/11
to google-iden...@googlegroups.com
The replies are inlined.

On Wed, Aug 3, 2011 at 12:43 PM, Vaishakh Thayyil <vaish...@gmail.com> wrote:
Thanks Jinhui Du for your quick repsonse ,

I have already seen this links , what I am stuck with is to use those libraries, 

I have customized those javascript code with all the necessary URL's . 

I have set callback URL to the callback.php page in the package I have 

downloaded . I am not at all clear with the callback procedure 

 
In this line "Your server needs to call the verifyAssertion API to validate the IDP's response "

it says you have to call the verifyAssertion API to verify the response , how do I do it using the 

packages ?

The client library handles the verifyAssertion request in the file git/util/gitApiClient.php
You can see the source code of the callback page of the sample OpenCart app. The file is catalog/controller/account/callback.php in the package.
The IDP redirects the user to the callback page with the assertion. The callback page accepts that and sends it to the API server to verify the assertion.

 

The  callback.php page contains takes 2 get request $_GET['rp_input_email'] & $_GET['rp_purpose']

I tried calling callback.php page directly with rp_input_email=vaish...@gmail.com ,what is rp_purpose

for ? Is there any documenation or guide regarding what php files are used for what ? Any one sample 

The 'rp_purpose' is used to differentiate where the user in the widget starts the federated login. We're in the process to remove it.

Vaishakh Thayyil

unread,
Aug 4, 2011, 5:26:35 AM8/4/11
to google-iden...@googlegroups.com
Some progress set my key in git/util/gitApiClient.php file , 
ran my javascript widget and succcesfully logged into my 
gmail account , I  also got messages "Redirecting to IDP" ,but then I got this .

 signin.png

I checked my log files in php  it says a get Request was made to the callback.php page .

Here's the log "GET /accounts/callback.php?rp_target=callback&rp_purpose=signin&gx.rp_st=AEp4C1t2sP17q0sMmRcVipchpvUKZWtx9qjLOHQm0LRW09saSp-lFqyUA2N7Y8RQxoMnvV0T82LY-Unt80u7LEDvrQ9Hnx0p5WYwee5-xbYMInuIK1cRK-XK9IpkpfeXNQ7whC4EHRly&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=id_res&openid.op_endpoint=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fud&openid.response_nonce=2011-08-04T08%3A00%3A39ZKE2atCDsWmHKCA&openid.return_to=http%3A%2F%2Flocalhost%3A81%2Faccounts%2Fcallback.php%3Frp_target%3Dcallback%26rp_purpose%3Dsignin%26gx.rp_st%3DAEp4C1t2sP17q0sMmRcVipchpvUKZWtx9qjLOHQm0LRW09saSp-lFqyUA2N7Y8RQxoMnvV0T82LY-Unt80u7LEDvrQ9Hnx0p5WYwee5-xbYMInuIK1cRK-XK9IpkpfeXNQ7whC4EHRly&openid.assoc_handle=AOQobUdLwj_jjT0BVNMXd6nUUB01XE9QGgV6oHIGFgDVe1pDrjUOjGpj&openid.signed=op_endpoint%2Cclaimed_id%2Cidentity%2Creturn_to%2Cresponse_nonce%2Cassoc_handle%2Cns.ext1%2Cext1.mode%2Cext1.type.attr3%2Cext1.value.attr3%2Cext1.type.auto2%2Cext1.value.auto2%2Cext1.type.attr0%2Cext1.value.attr0%2Cext1.type.attr9%2Cext1.value.attr9%2Cext1.type.attr6%2Cext1.value.attr6&openid.sig=Qoel%2BkegYUOu74MQCGbQepqyc2I%3D&openid.identity=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawlEBpzwseElP7PqSUfP_NmUIHyjgISZbrA&openid.claimed_id=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawlEBpzwseElP7PqSUfP_NmUIHyjgISZbrA&openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0&openid.ext1.mode=fetch_response&openid.ext1.type.attr3=http%3A%2F%2Faxschema.org%2FnamePerson%2Ffirst&openid.ext1.value.attr3=Vaishakh&openid.ext1.type.auto2=http%3A%2F%2Fwww.google.com%2Faccounts%2Fapi%2Ffederated-login%2Fid&openid.ext1.value.auto2=116442347671250700902&openid.ext1.type.attr0=http%3A%2F%2Faxschema.org%2Fcontact%2Femail&openid.ext1.value.attr0=vaishakh.r%40gmail.com&openid.ext1.type.attr9=http%3A%2F%2Faxschema.org%2Fpref%2Flanguage&openid.ext1.value.attr9=en-GB&openid.ext1.type.attr6=http%3A%2F%2Faxschema.org%2FnamePerson%2Flast&openid.ext1.value.attr6=Thayyil HTTP/1.1" 200 2690 "http://localhost:81/accounts/accountlogin.php "


what I have realized is that the callback contains my email id and all necessary information in it . 
Do I have to get the value of each parameters to proceed . What does this URL signify ,is my user
registered ? Since I have made a  userstatus.php page with default json '{"registered": true}'  every 
email id is returned as registered , but my log doesn't indicate any call made to this page .


I haven't created other php pages login,signin,signout  . Is callback.php page lind of endpoint and I 
have to handle the rest of files by myself ?

Thanks Jinhui 
 






signin.png
userstatus.php

Billiam James

unread,
Aug 4, 2011, 7:31:36 AM8/4/11
to google-iden...@googlegroups.com
Hi Vaishakh,

I am at the same position as you... 

I am not using the opencart sample. I am using the GIT PHP Client Library and integrating it with a WordPress installation.

This is what I have done:

1. Put GIT Javascript widget into WordPress
- Loaded the JQuery and Googlle API;'s in the header.
- Put the GIT JS code in header, and configured it for my server
- Added GIT "div" to the login position on page

2. Put GIT PHP Client Library on server
- Put the complete "git" folder (GIT PHP Client Library) the on server (e.g. http://yoursite.com/git/)
- Callback location matches location specified in GIT JS Code (e.g. http://yoursite.com/git/callback.php)

3. Edited config file /config/config.php
Specify location of names of local implementation files:
'externalClassPaths' : the names of the folder where your 'accountService'  and 'sessionManager' implementation are stored. I put my files in the in git existing '/git/session' and '/git/data' directories
'externalClassPaths' => 'session,data',

'accountService': The name of your implementation of your local php AccountService. For example, if your file is named "myAccountService.php" it would be configed as:
'accountService' => 'myAccountService',
This accountService file implements the three functions named in the 'gitAccountService' implementation (see: gitAccountService.php)

'sessionManager': The name of your implementation of your local php SessionManagerGIT PHP Client Library included a sample seesion implementation: "gitSessionBasedSessionManage.php" which I have used as a starting point.
sessionManager' => 'gitSessionBasedSessionManager'


At this point the the GIT Toolkit works for me, in that it connects to the IDP (gmail) and returns the user's data.

4. Use your local Implementation files to integrate IDP data with your site
The next step is to take this the IDP data (e.g. users gmail account info), and use it to log in to the your local site, start a session, and save the user's account info. I think this should be donw customizing the /git/myAccountService.php and git/gitSessionBasedSessionManager.php files so that the take the IDP data and merge it with your site.

This is what I am working on now...

Vaishakh Thayyil

unread,
Aug 4, 2011, 9:26:09 AM8/4/11
to google-iden...@googlegroups.com
Thanks Billiam ,

That was truly a advice in the right direction , very well written and really helpful .

I have began to work on point 3 .

I have one silly doubt though , in the javascript login widget I specify the userstatusUrl ,

so here after having implememnted the AccountService.php class , I need to call its getAccountByEmail()

function and give back a suitable json response in the userstatusUrl given , am I right ?


After everything goes fine ,it should landup in my callback page with all the parameters ,

thats when I set the session using the values derived from parameters . 

A better documentation by Google on this php sample code would be help . 

Anywayz thankyou Jinhui and Billiam for taking your time out . I will surely give it a try 

and post a sample implemenation if I am successful .

Thanks 

Vaishakh

Billiam James

unread,
Aug 4, 2011, 10:46:26 AM8/4/11
to google-iden...@googlegroups.com
Re: Difference between userstatus and getAccountByEmail()

userstatusUrluserstatusUrl checks if user exists, and returns a JSON String

If the user exists, return: {"registered": true
If the user does not exist, return: {"registered": false}

For example: If "te...@gmail.com" is an account on your site, then the userstatusUrl (http://yoursite.com/git/userstatus.php?email=te...@gmail.comshould return this:
{"registered": true}

getAccountByEmail() 
getAccountByEmail() checks if user exists, and returns a gitAccount Object

If the user exists, you need to load the user data from your local site and put it into a gitAccount object (as defined in /git/data/gitAccount.php), then return that object

If the user does not exist, return null.


That is how I understand it, anyways...

Stephan Vierkant

unread,
Jan 18, 2012, 8:24:53 AM1/18/12
to google-iden...@googlegroups.com
I've got the same problem (Fatal error: Call to a member function getAccountByEmail() on a non-object in/home/***/domains/***/public_html/git/logic/gitCallbackLogic.php on line 44).

How do I set up config.php?

Abdulquadir Lokhandwala

unread,
Oct 29, 2012, 9:44:02 AM10/29/12
to google-iden...@googlegroups.com
Hello Billiam!!

I am facing same problem 'Fatal error: Call to a member function getAccountByEmail() on a non-object in C:\wamp\www\cls\code\git\logic\gitAccountStatusLogic.php on line 19'   I tried to implement solution suggested by you but still no luck please can you help me in this..

Thanks in advance..

Abdulquadir

Jin Liu

unread,
Oct 29, 2012, 8:43:01 PM10/29/12
to google-iden...@googlegroups.com
The getAccountByEmail() is a function of interface class GitAccountService, which is expected to be implemented by the site developer. Refer to Google Identity Toolkit Drupal plugin code to see an example of the implementation, and the sample context loader to bind your implementation to the GitContext.

Billiam James

unread,
Oct 29, 2012, 8:46:02 PM10/29/12
to google-iden...@googlegroups.com

Sajjad Yousuf Anjum

unread,
Dec 11, 2012, 8:33:19 PM12/11/12
to google-iden...@googlegroups.com
HI, Billiam James 
Can you share your code, i m getting problem, i m login successfull but i dont know how get the response data and user profile information
thank.

Billiam James

unread,
Dec 13, 2012, 5:59:09 AM12/13/12
to google-iden...@googlegroups.com
Sajjad.

I am switching to GIT V2, You can see sample PHP code here:
https://developers.google.com/identity-toolkit/v2/acguide

If you are still working GIT v1 look at this code:

Billiam
Reply all
Reply to author
Forward
0 new messages