0

I am creating a php laravel application that requires google oauth to work. So I created the following function:

function auth(){
   $client = new Google_Client();
   $client->setClientId($client_id);
   $client->setClientSecret($client_secret);
   $client->setRedirectUri($redirect_uri);
   $client->addScope("https://www.googleapis.com/auth/adsense.readonly");
   $authUrl = $client->createAuthUrl();
   return "<a href=\"$authUrl\">Connect Me</a>";
}

Now I want to access this $client variable when the user comes back on my site. Since my Session becomes empty after the redirect, I can't use that. (maybe something to do with the response being in HTTPS).

The two options I have considered are: 1) Cookies 2) Making the redirect url have the session id as a param (not sure if this can work)

Is there any standard way to achieve this?

3
  • Sessions should work. How are you using them? Commented Feb 10, 2015 at 12:29
  • I do Session::put('client', $client); before returning $authUrl. On the other side, I do $client = Session::get('client'); but this comes out to be empty. Could this be because my auth() function is served over http and the redirect response uri is a different url that comes over https? Commented Feb 10, 2015 at 15:17
  • There is a package "adamwathan/eloquent-oauth-l5" which handles also google oauth. If you dont want to use it maybe you find your answere here. Commented Aug 26, 2015 at 8:46

1 Answer 1

1

I suggest taking a look at http://oauth2-client.thephpleague.com/

There are code samples on it and it gives you good understanding of what you will need to do.

Alternatively take a look at Laravel's Socialite

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.