Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google authentification always ask authorization despite prompt has no value

After having connected a user from Google OAuth, when this one wishes to reconnect during a next session requiring the selection of his google account, the permission is asked again.

According to the documentation, the behavior of the parameter prompt that is responsible for authorization requests is as follows:

If no value is specified and the user has not previously authorized access, then the user is shown a consent screen.

The user should therefore not have to reorder his consent (with verification, the application is present in my authorizations).

The only answer envisaged was the one on this question : login with google always asks user consent

Because I also work locally without secure HTTP, but he assumes that a cookie policy is present which is not the case.

Code generating URL

/**
 * Create a new OAuth2Client with the credentials previously loads
 */
private getOAuth2() : OAuth2Client {
    return new OAuth2(
        this.credentials.client_secret,
        this.credentials.client_id,
        this.credentials.redirect_uris[0]
    );
}

/**
 * Create connection URL for the given scopes
 * @param scopes
 */
public url(scopes: Array<string>) : string {
    return this.client.generateAuthUrl({
            access_type: "offline",
            scope: scopes
    });
}



// The scope used to generate URL is 'https://www.googleapis.com/auth/youtube.readonly'

// this.client refer to a client which is load by getOAuth2
// and use only for the generation of URL's.

When a user logs in a second time, to obtain a refresh token that has been lost, he or she is not required to give consent again :

enter image description here

And that is the problem which occur.

like image 666
Neok Avatar asked Aug 29 '18 17:08

Neok


1 Answers

TBH, I didn't understand your problem clearly. But, I'm sure that you must be dealing with two different tokens. As it is OAuth, at first you'll get access token from Google upon successful user authentication.

You're supposed to use that access token to get user information from Google. But by default access token has some expiration time, beyond which the user has to reauthorize your app. I suspect that's what happens in your case.

You can renew your access token by making use of refresh token which you'll get when you get consent from the user.

You can get detailed information in this blog post written by me, https://www.syncwithtech.org/authorizing-google-apis/

I hope this may help you in some way.

like image 90
vicke4 Avatar answered Sep 27 '22 18:09

vicke4