Cookie causes OAuth failure with G+ API

Discussion in 'Google API' started by ZapoTeX, Oct 31, 2011.

  1. #1
    Hi everyone! This is my second post on this great forum and I have a question that is extremely difficult for me, but I hope it is really easy for you! :)

    I'm trying to get familiar with Google Plus APIs (in particular with the PHP implementation).

    When the user gets to my page (similar to the Google Plus API PHP starter), my app needs the authorization to access the user's profile. I set the page itself as the callback URI. Initially, everything worked perfectly: the user clicks on the login link, authorizes my app, then comes back to my page with successful authorization ($authUrl is not set, while $me and $activities are set).

    However, now I need to pass a parameter called 'id' from BEFORE the authorization to AFTER and this seems to MESS EVERYTHING UP :-(

    If there is a session variable or a cookie when the authorization request is sent, the user comes back to my page without the authorization ($authUrl is set, while $me and $activities are NULL).

    Even more weird: after using

    setcookie('storedid', $_GET['id'], time()+3600, '/', '.mydomain.com');
    Code (markup):
    the user comes back WITHOUT authorization, while with:

    setcookie('storedid', $_GET['id'], time()+3600, '/anysubfolder/', '.mydomain.com');
    Code (markup):
    it works perfectly! Also, at some point I made a typo and $_GET['id'] was NULL and, even if the cookie was in the '/' path, the authorization was successful!

    Is there a way I can pass a parameter from before to after the authorization? I can't use a get or post method, because the Google page the user is sent to can't parse my id parameter and send it back to my page afterwards.

    I'm starting to think about crazy stuff (writing the 'id' to a SQL table, together with the user's IP address and retrieving it with a query after the authorization) but it is not robust and frankly it would suck!

    Sorry for long post and thanks to everyone who will look into my problem!

    Davide
     
    ZapoTeX, Oct 31, 2011 IP