Get refresh token google api
Found out by adding this to your url parameters
approval_prompt=force
Update:
Use access_type=offline&prompt=consent
instead.
approval_prompt=force
no longer works
https://github.com/googleapis/oauth2client/issues/453
Get access token using Refresh token through google API using NodeJS
in the line where we storing a google account in MongoDB I was referencing access token to refresh the token field.
const googleUser = await GoogleAccount.create({
refreshToken:tokens.refresh_token, //tokens.access_token this was the issue so changed access_token to refresh_token
id_token: tokens.id_token,
isActive: true,
user: userId,
name: data.name,
email: data.email,
googleId: data.id,
imageLink: data.picture,
});
How to get refresh token while using Google API JS Client
It does not return a refresh token as designed. The tutorial and the code you mentioned are using Google APIs Client Library for JavaScript. This library uses the OAuth 2.0 client-side flow for making requests that require authorization.
As The OAuth 2.0 Authorization Framework says:
The implicit grant type is used to obtain access tokens (it does not support the issuance of refresh tokens) and is optimized for public clients known to operate a particular redirection URI. These clients are typically implemented in a browser using a scripting language such as JavaScript.
In fact, The authorization code flow is the only one which issue refresh token, and Google supports this flow in these Scenarios: Web server applications, Installed applications, and Applications on limited-input devices, but not Client-side (JavaScript) applications or Service accounts. Get more details from here.
So you'll not get refresh token in this way.
Related Topics
Correct File Permissions For Wordpress
Convert Flat Array to a Delimited String to Be Saved in the Database
PHP: Is MySQL_Real_Escape_String Sufficient For Cleaning User Input
PHP Function to Get the Subdomain of a Url
Pdo MySQL: How to Know If Insert Was Successful
PHPmailer - Smtp Error: Password Command Failed When Send Mail from My Server
How to Fix the Session_Register() Deprecated Issue
How to Make a PHP Soap Call Using the Soapclient Class
Performance of For VS Foreach in PHP
"The Page Has Expired Due to Inactivity" - Laravel 5.5
How to Upload Multiple Files Using PHP, Jquery and Ajax