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

option to work without a logged in user #15

Open
philcruz opened this issue May 29, 2015 · 8 comments
Open

option to work without a logged in user #15

philcruz opened this issue May 29, 2015 · 8 comments

Comments

@philcruz
Copy link

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?

@tmeasday
Copy link
Member

Hmm.

So the idea would be to be able to pass in a refreshToken and an updateAccessToken function and have the default implementation be user.services.google.refreshToken and something like Meteor.users.update(user._id, {$set: {'services.google.accessToken': X}}) ?

Is everything happening server-side here for you also? (i.e. we don't publish the refreshToken, call a method to update it).

@zol: what are your thoughts about accepting a PR for this? It adds complexity to the package but it seems a legit use case...

@philcruz
Copy link
Author

To clarify, the way I have it working is if you pass in options.user then it works as you have it. Alternatively, if you pass in options.refreshTokenParams like in my example so you can manually manage the tokens. This way it should be backwards compatible.

@zol
Copy link
Member

zol commented Jun 9, 2015

@tmeasday @philcruz - I can see how this would be useful. On the other hand, it's also kind of an edge case given that most do use Meteor accounts. Given that we haven't received requests for this, I would suggest forking the package for now and using it as a submodule in your project. If we receive more requests for the functionality, we'll extend the package.

@ganySA
Copy link

ganySA commented Jun 20, 2015

I have a very similar requirement.
@philcruz did you eventually publish any code, are you using meteor package oauth flow to get the initial tokens? i am looking for something to create the initial request + something to auto refresh

@philcruz
Copy link
Author

@ganySA I haven't published my fork yet but I will. I can't do it this week because I'm on travel. I'll do it the following week.

@philcruz
Copy link
Author

@ganySA You can check out my code at https://github.com/philcruz/meteor-google-api/tree/develop

@phsultan
Copy link

Hi everybody,

I'm using @philcruz package, and I found it very useful to access Google's API (contacts in my case), as the single source of Meteor accounts I have for my users isn't Google.

So I vote for adding this extension if this is something you guys would consider.

@lvnr
Copy link

lvnr commented Jan 29, 2016

@tmeasday @zol - I develop a dashboard app, where multiple oAuth tokens to multiple services are saved to dashboards, and not to Meteor accounts (since there might be multiple users using the same dashboard). So I assume this is a somewhat generic requirement other people might have and I would really like to see this implemented.

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

6 participants