-
Notifications
You must be signed in to change notification settings - Fork 229
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
Message: [AuthenticationError.OAUTH_TOKEN_HEADER_INVALID @ ; trigger:'<null>'] when using refresh token #39
Comments
@mcloonan is currently maintaining the library. You are very welcome to send a pull request, please see: https://github.com/googleads/google-api-ads-ruby/blob/master/adwords_api/CONTRIBUTING.md |
I found the same error on running https://github.com/googleads/google-api-ads-ruby/blob/master/adwords_api/examples/v201506/misc/use_runtime_config.rb with refresh token. |
Thank you for the report, and I apologize that this slipped through the cracks. Since it seems @huydx may not be providing the pull request, I'll take a look at implementing a solution myself. |
I worked around this by providing an expires_at value in my config. The problem is that if the OAuth2 client doesn't have that value it's never going to be considered expired and the access token won't be generated. |
@offthecuff Could you please be more specific? What is the exact place where did you provide |
@Gataniel, It goes in the adwords = AdwordsApi::Api.new({
:authentication => {
:method => 'OAuth2',
:oauth2_client_id => client_id,
:oauth2_client_secret => client_secret,
:developer_token => developer_token,
:client_customer_id => client_customer_id
:user_agent => user_agent,
:oauth2_token => {
:refresh_token => refresh_token,
:expires_at => 0
}
},
:service => {
:environment => 'PRODUCTION'
}
}) |
This is the issue in a nutshell. This method will return false if expires_at is nil. def expired?
return self.expires_at != nil && Time.now >= self.expires_at
end At this point the client is not nil, but it will not be expired either so no token is created. def get_token(credentials = nil)
token = super(credentials)
token = refresh_token! if !@client.nil? && @client.expired?
return token
end To me this honestly seems like a deficiency in the signet gem, but I suppose this might be the intended behavior. |
Since there's a workaround and the issue seems to be with Signet, I'm going to close this out. It might be worth filing a bug with Signet directly if this is still an issue for you. |
Using the example from :
https://github.com/googleads/google-api-ads-ruby/blob/master/adwords_api/examples/v201409/misc/create_ad_words_session_without_properties_file.rb
I've got the following error:
However, if I'm authenticate by web and renew the access token by hand, saved to file, everything just going fine.
Can you guy trouble shoot the error.
Thank you very much.
Add:
After a while digging the code, I think the reason is that in the sample code:
by setting
oauth2_token => {:refresh_token => refresh_token}
,it make developer think that implicit setting like this, will make the library to get access token by using refresh token.
But follow the code in ads-common :
it only using refresh token when @client nil or expired, and not check the credential.
I think the correct behaviour should be: [when refresh token present and access token not, it use refresh token to refresh access token.]
What do you maintainers think about this situation.
If it's fine, i would like to make a pull request
The text was updated successfully, but these errors were encountered: