So I'm working with the Google APIs in a project and came across this package. It's nice that if the call fails it refreshes the token and retries the call for you. However, it's dependent on having a logged in user. You pass options.user and under the hood it fetches/updates from user and user.services.google.
In my project I'm handling OAuth manually so I don't have a logged in user. I would still like to have the refresh-retry functionality though. So I made some modifications that do that. Instead of passing in options.user you would pass options.refreshTokenParams
updateAccessToken = function(access_token) {
console.log("in updateAccessToken");
Tokens.upsert(
{account: Meteor.settings.account},
{ $set:
{
accessToken: access_token
//expiresIn: result.data.expires_in
}
}
);
}
options = {
refreshTokenParams: {
'client_id': Meteor.settings.public.client_id,
'client_secret': Meteor.settings.client_secret,
'refresh_token': tokens.refreshToken,
'updateTokenFunction': updateAccessToken
},
params: { 'access_token': tokens.accessToken }
}
result = GoogleApi.get( apiUrl, options);
Seem like a good approach?
So I'm working with the Google APIs in a project and came across this package. It's nice that if the call fails it refreshes the token and retries the call for you. However, it's dependent on having a logged in user. You pass options.user and under the hood it fetches/updates from user and user.services.google.
In my project I'm handling OAuth manually so I don't have a logged in user. I would still like to have the refresh-retry functionality though. So I made some modifications that do that. Instead of passing in options.user you would pass options.refreshTokenParams
updateAccessToken = function(access_token) {
console.log("in updateAccessToken");
Tokens.upsert(
{account: Meteor.settings.account},
{ $set:
{
accessToken: access_token
//expiresIn: result.data.expires_in
}
}
);
}
Seem like a good approach?