shikhar.ja
shikhar.ja

Reputation: 467

Google+: Get access_token for already authorized accounts through PHP client library

I am implementing the hybrid sign in flow got login with Google+. What I want to achieve is this:

One a user has authorized the app, the next time he comes back on the website, I want to log him in automatically.

In hybrid flow, google automatically logs the user in and displays a welcome back message (javascript sdk) along with returning access token. But this process requries one ajax call to be sent to gogole api.

I want to make this call through the backend itself using Google's PHP client library. Since the app has been authorized already, it should simply return the access token as it does when using javascript sdk. But I am not able to figure out how to achieve this using client library. Can anyone please help me out?

Upvotes: 1

Views: 186

Answers (1)

Klemen Tusar
Klemen Tusar

Reputation: 9689

In your call parameters set access_type: 'offline', then need to get a new token using the refresh_token that is provided ONCE at the FIRST time of authorisation. You will have to store that refresh_token somewhere in your database and pair it up with the user's already expired access token ID or somehow and make another call for a valid access token.

For the time being you can set approval_prompt: 'force' but that's merely a development trick not a real solution.

More is explained here refresh token with google api client php

Upvotes: 1

Related Questions