Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No refreshToken at first login #394

Open
Saqib92 opened this issue Sep 9, 2024 · 0 comments
Open

No refreshToken at first login #394

Saqib92 opened this issue Sep 9, 2024 · 0 comments

Comments

@Saqib92
Copy link

Saqib92 commented Sep 9, 2024

I need refreshToken at the time of login (Web, Android, IOS) in all the platforms.
I need to use some google API's. Specifically spreadsheet API to read and write data. Currently, using access_token is working fine but it expires after 1 hour. i need to updated access_token.

My backend nodejs:

const { google } = require('googleapis');

app.post("/test", (req, res) => {
    refreshAccessToken(req.body.refreshToken); // but this is working for access_token not for idToken and there is no refreshToken
    res.json({ updated_token: "world" });
});


async function refreshAccessToken(refreshToken) {
    const OAuth2 = google.auth.OAuth2;
    const CLIENT_ID = '';
    const CLIENT_SECRET = ''
    const REDIRECT_URI = 'https://developers.google.com/oauthplayground';

    const oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI);
    oauth2Client.setCredentials({ refresh_token: refreshToken });

    try {
        const newCredentials = await oauth2Client.refreshAccessToken();
        oauth2Client.setCredentials(newCredentials);
        console.log('newCredentials', newCredentials);
        //console.log('Access token refreshed successfully:', newCredentials.access_token);
        // Use the updated access token for your API requests
    } catch (err) {
        console.error('Error refreshing access token:', err);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant