Skip to content
This repository has been archived by the owner on Dec 31, 2019. It is now read-only.

A refresh_token is not available #21

Closed
telmogh opened this issue Jan 8, 2017 · 7 comments
Closed

A refresh_token is not available #21

telmogh opened this issue Jan 8, 2017 · 7 comments

Comments

@telmogh
Copy link

telmogh commented Jan 8, 2017

Hello all,

me again 😞

I'm getting A refresh_token is not available.

So, this happens once the OAuth has been authenticated, and we try to hit the endpoint on Google again.

I've debugged the code and tried to run client.refresh_token, no luck here.

Any ideas?

@thegengen
Copy link
Owner

Hi, and thanks for reporting. Could you share a snippet of the code you're using (or at least the code you're using to debug the issue?)

Thanks.

@telmogh
Copy link
Author

telmogh commented Jan 9, 2017

Hi there,

I have this

client = CloudPrint::Client.new(client_id: Settings.google.cloudprint.key, client_secret: Settings.google.cloudprint.secret)
redirect_url = Settings.urls.root + "/cloudprint/callback"
token = client.auth.generate_token(params[:code], redirect_url)

When running the last line is when I get the error.

@thegengen
Copy link
Owner

OK, so I take it that the third line is in a separate controller under the callback action for CloudPrint. Have you confirmed that params[:code] is not nil when you try to generate the token?

Also, I'm not sure what you mean by 'we try to hit the endpoint on Google again.' Generating the refresh token can only be done once -- after the very first time users sign in, when they are redirected back to your application. You have to save the token there and then and reuse it from that point on.

@telmogh
Copy link
Author

telmogh commented Jan 11, 2017

The params[:code] is not nil, I've checked.

So, a User in my application can have multiple Organization, for each Organization I need to allow access to Google Cloud Print, but since they already gave access for, lets say, the first Organization, it doesn't work for the second one.

@thegengen
Copy link
Owner

OK, so are you trying to generate more than one refresh token from the same code? Because that won't work. If that's what you're trying, you should share the refresh token between multiple orgs instead.

If not, I'm afraid I'll need to see a minimal example that I can run on my end to reproduce this bug.

@telmogh
Copy link
Author

telmogh commented Jan 11, 2017

Ok, I'll change the code on my end and try a different approach, thanks 👍

@telmogh telmogh closed this as completed Jan 11, 2017
@troelskn
Copy link
Contributor

troelskn commented Jan 3, 2019

For future reference, since I spent some time figuring this out: If you try to re-auth, it will fail, because you already have received a valid authentication previously. To work around this, append &prompt=consent to the auth_url. E.g.:

client.auth.generate_url(redirect_url) + "&prompt=consent"

We might want to make this default behaviour and/or document it in the readme.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants