Skip to content

No refreshToken at first login #394

Description

@Saqib92

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);
    }
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions