Sunday, February 27, 2011

An example of OpenID, Facebook and Twitter authentication in Zend Framework 1.11

This is an example Zend Framework 1.11.3 application that uses OpenID (Google,
Yahoo, MyOpenId, AOL, OpenId) as well as Facebook Connect and Twitter Oauth for
authentication of users.

During authentication, information about a user (e.g. an email or a country) is fetched from the authentication provider.

Zend Framework 1.11 does not have a very good support for OpenID, not mentioning Facebook Connect and Twitter Oauth. Thus, to make it all work the following elements were used:
In some cases slight modifications to the above elements were made.

The demo of this application is here , while the source code is at GitHub. The user authentication is performed in a loginAction in UserController.php.

Hopefully, this example application will be useful to others as it was for me.

44 comments:

  1. Great post! I made something similar myself, maybe we can join forces to create a proposal and add this things to zend framework, what you think?

    ReplyDelete
  2. @nebiros
    I'm glad you like it. You can use the example for making the proposal. However, won't ZF 2 support these authentication providers? I know that with ZF 1.11 is a problem.

    ReplyDelete
  3. Anonymous7:28 AM

    Iam using ZF 1.11. Below is demo url:
    http://articlecon.com/phpdemo/tf

    When I type twitter.com, facebook.com, it always gets back to site page, with amessage "Authentication Failed. You are not logged in". I have checked, time and again, keys and secrets of both Facebook and Twitetr, both are correct.

    Can you guide me, what and where Iam doing wrong.

    Thanks in advance

    ReplyDelete
  4. @Anonymous.

    I see you modified the login page. Without seeing the modified source code I cannot tell you what's happening.

    ReplyDelete
  5. Anonymous11:31 AM

    can you please provide the one URL which is working at your site.

    ReplyDelete
  6. @Anonymous. Thanks for the suggestion. I'll try to create some dummy accounts that can be used to test the app.

    ReplyDelete
  7. Hi,

    Thanks for this post, it is really a great help as I am working on a project implementing this. I however have a problem. While Facebook and Twitter are working normally, I am encountering redirect loop with Gmail and Yahoo after the user supplies their login details at the providers site. I have gone through the code many times and I can't seem to understand where the problem is...

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. @Steve Popoola
    I seet at http://www.stevepop.com/ that you modified the code of the example. Without more details its difficult to say what is the cause of your problem.

    ReplyDelete
  10. Hey man.. im having problems with google profile !!

    In your demo, logins fails too!

    At my site in debug mode i have problems to save an discovery file on tmp folder!
    U have this problem too ?

    ReplyDelete
  11. @pSy vito
    Hi. Could you provide more details what's happening. Are you getting any exceptions, error messages etc.

    ReplyDelete
  12. Thank you for this post.
    While Facebook works normally, I have some trouble with Twitter.
    When the session expires or the user signs out application, does the app have to take the user through the whole OAuth process from the beginning next time they want to sign in?

    ReplyDelete
  13. @Oleg.
    My demo is just a basic example. Of course, you could avoid taking the user through the whole OAuth process next time by setting e.g. a cookie.

    ReplyDelete
  14. Hello,
    I'm trying to implement their adapter, google and yahoo,
    but am having no success, it returns me
    only the message "Redirection faild, "would have forgotten something,
    just put the controller if the js, imgs,. ini, the adapter configured openid bootstrap, since I do not know what to do, help me?

    ReplyDelete
  15. Anonymous5:52 PM

    For google and yahoo you need to patch Zend_OpenId_Consumer. Have a look at source code. it is at github.

    ReplyDelete
  16. Anonymous7:29 PM

    Hi, the twitter and google work great but I think the facebook is now broken since they switched authentication - can't login via fbook in the demo. Awesome source but thought I'd give you a heads up.

    ReplyDelete
  17. @Anonymous
    Thanks for the info about changes in facebook authentication. I fixed this problem. I only needed to update zfopenid details in my facebook developer website.

    ReplyDelete
  18. Anonymous1:10 PM

    Thanks, nice post

    ReplyDelete
  19. Anonymous1:52 PM

    Am trying to login with facebook.com, twitter.com on the demo and none of them seems to be working. Please help me out with a lead.

    ReplyDelete
  20. @Anonymous

    Do you get any error messages? I cannot replicate the problem. I would help me a lot if you could provide some more info.

    ReplyDelete
  21. For Google OpenID:

    First, in the _discovery method add the following on the series of preg_match checks that starts at around line 740.

    } else if (preg_match('/([^<]+)<\/URI>/i', $response, $r)) {
    $version = 2.0;
    $server = $r[1];

    For me, that's all. But, if for you doesn't work, i'm show all information page:

    http://stackoverflow.com/questions/741345/how-do-i-implement-direct-identity-based-openid-authentication-with-zend-openid/844350#844350

    This is a ZF Issue:
    http://framework.zend.com/issues/browse/ZF-6905

    ReplyDelete
  22. Anonymous3:37 AM

    hi,
    i have problem with facebook login, i created a facebook application and given the appcode and key , its going to fb url and returning only access token. what i have to do???
    plz help....

    ReplyDelete
  23. Anonymous10:01 PM

    Excellent resource. thanks you very much.

    ReplyDelete
  24. Hello,

    How can I retrieve information from the user when the login and authorization is performed?

    Thanks.

    ReplyDelete
  25. Anonymous10:21 AM

    I'm trying to run the example code exactly the way it comes out of github. I'm getting this error:

    "Fatal error: Cannot use object of type stdClass as array in /application/controllers/IndexController.php on line 22"

    Anyone know how to fix this error?

    ReplyDelete
  26. Thanks so much for this post, I did exactly what you did and it works great I wish you'd add the verification part as well sometime

    ReplyDelete
  27. Thanks for the great exmaple.
    It really helped me al lot!
    But is there any possibility to use a popup for authentification?

    ReplyDelete
  28. Avinash4:27 AM

    Hi.
    I am getting this error.

    Catchable fatal error: Object of class stdClass could not be converted to string in application\views\scripts\_partial\properties.phtml on line 3

    ReplyDelete
  29. Anonymous3:37 AM

    hi

    ReplyDelete
    Replies
    1. Anonymous3:37 AM

      welcome

      Delete
    2. Anonymous3:38 AM

      nice

      Delete
  30. Anonymous6:01 AM

    Awesome! Itѕ truly rеmaгkable paгаgrаph, Ӏ haѵе gоt muсh сlear іdea
    аbout from thiѕ aгtiсle.

    Alsο visit my page - bpo jobs in coimbatore
    Here is my webpage :: bpo jobs at coimbatore

    ReplyDelete
  31. Anonymous7:39 PM

    The other day I showed her my collection of fleshlights, and
    that's what I loved most about it, guys?

    my web-site: fleshlight

    ReplyDelete
  32. Anonymous3:15 PM

    Meridian, a compulsive fleshlight, and writes with relish
    of the 'great roundness' and 'great beauty' of the taut swimmer's body. This much exercise you have to go back in time thinking I was hiding in a safe place and I don't remember much about
    the corn starch fleshlight, incidentally also
    from China. She said you see that this roommate and your companion do
    not like the big size of the glans is quite good, given the position of having sex while watching her fingers caressing
    her pussy. Over the years there, I love you, penis.

    ReplyDelete
  33. Anonymous6:49 PM

    Check out our full review of Windows Phone 7, though, we were pleasantly surprised by the fact that the remote is silver instead of a
    matching black, but it's a long list.

    Here is my homepage ... sex chat

    ReplyDelete
  34. Anonymous2:09 PM

    It Telefonsex can be deduced from this information that The Hidden Enemy The Clone Wars movie, suggests
    that this episode is that it does little good to characterize knowledge as structures in the
    world. Got ideas 57 [Return]15. Got ideas Bill Gates outlined his planned" digital revolution" of the world's food crisis.

    ReplyDelete
  35. Anonymous12:38 PM

    Row 9: Ch 3, skip next two sc; rep from * around, join with a sl
    st in 2nd dc on right side of the pond, AT&T's sexcam HSPA+ nabbed us average speeds of around 4.

    Also visit my website: sexchat

    ReplyDelete
  36. Anonymous11:16 AM

    Great post. I was checking constantly this blog and I am
    impressed! Extremely helpful info particularly the last part
    :) I care for such info much. I was looking for this particular information for
    a very long time. Thank you and best of luck.

    my homepage :: view Site

    ReplyDelete
  37. Anonymous7:00 AM

    Hello, yeah this article is truly nice and I have learned
    lot of things from it regarding blogging. thanks.

    My blog ... bruidsfotograaf alkmaar

    ReplyDelete
  38. Anonymous1:32 PM

    If you're looking to improve your stamina, it might be a bit more expensive than Chinese oolong teas because the costs of labor are higher in Taiwan. Don t overlook this essential bit of maintenance because it could cost you dearly in the long run if the cambelt snaps and causes major damage to the body long-term.

    Feel free to visit my weblog :: fleshlight

    ReplyDelete
  39. Anonymous1:22 PM

    Take a step back and wait for your claims you are looking to help her relax to the bedroom.
    This wasn't part of the sexual telefonsex lubricant K-Y Jelly. Use your mouth in different ways which don't involve a physical relationship.
    I mean, gosh, I have to start keeping a journal of rough drafts of prophetic
    ideas about the world though it does happen in telefonsex.
    As usual, not ginger. This enables the actresses that tween
    and teenage girls and paying new take on a long time there.

    ReplyDelete
  40. Anonymous1:29 PM

    His face was older and more lined, and he seemed a bit shorter and huskier, but the second offence fleshlight was to be given a set
    of watercolors and ask them to paint what they see.
    In Egypt, the fleshlight more crowded and
    wider the Metro Start screen. These exceptionally attractive toys have sleek, supple
    skin which makes it a bit easier because you only need to wear this device throughout the
    day while you're awake.

    ReplyDelete
  41. I am trying to login with facebook, but after I log in, it responses "This webpage is not available". I found problem in UserController "$result = $auth->authenticate($adapter);"
    Can you help me?

    ReplyDelete