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

Get new access token sometime before expiry #27

Closed
rocky-jaiswal opened this issue May 18, 2014 · 7 comments
Closed

Get new access token sometime before expiry #27

rocky-jaiswal opened this issue May 18, 2014 · 7 comments

Comments

@rocky-jaiswal
Copy link

Hi,

I recently attended the Adwords API workshop in Hamburg, there it was mentioned that it is ok to get a new access token before it expires (lets say 45 mins after it is issued).

However if you look at the code for OAuth2 handler for the ruby client (oauth2_handler.rb) -

  def get_token(credentials = nil)
    token = super(credentials)
    token = refresh_token! if !@client.nil? && @client.expired?
    return token
  end

  # Refreshes access token from refresh token.
  def refresh_token!()
    return nil if @token.nil? or @token[:refresh_token].nil?
    begin
      @client.refresh!
    rescue Signet::AuthorizationError => e
      raise AdsCommon::Errors::AuthError.new("OAuth2 token refresh failed",
          e, (e.response.nil?) ? nil : e.response.body)
    end
    @token = token_from_client(@client)
    return @token
  end

The code says that the token can be refreshed only after it is expired. See line 2 of get_token method.

Just wanted to check if this is intentional or a bug. For us it is important as we have built an OAuth2 service for all our client apps (like you recommended) and we want to send them fresh tokens not ones which are about to expire in 15 secs for example.

@TigerWolf
Copy link

You can trick the api client by modifying the date in the credentials which will give you a new token. This will temporarily get your feature working without changes to the api client.

@rocky-jaiswal
Copy link
Author

Ah ok. Thanks :)

@dklimkin
Copy link
Contributor

Actually, I'd like us to improve this. We need to add a library method to enforce the refresh.

@Sohair63
Copy link

Sohair63 commented Feb 24, 2017

Anyone resolved this yet ?

[INTERNAL_SERVER_ERROR] exception="OAuth2 token refresh failed" 
backtrace="/usr/local/rvm/gems/ruby-2.3.3/gems/google-ads-common-0.12.6/lib/ads_common/auth/oauth2_handler.rb:100:in `rescue in refresh_token!'

@dklimkin
Copy link
Contributor

Hi Sohair63, it's very likely this error is due to a local misconfiguration and not related to the enhancement here. Please reach out to the product (AdWords or DFP) support to look into your specific issue.
AdWords: https://groups.google.com/forum/#!forum/adwords-api
DFP: https://groups.google.com/forum/#!forum/google-doubleclick-for-publishers-api

@Sohair63
Copy link

Thanks @dklimkin

@mcloonan mcloonan reopened this Mar 13, 2017
@mcloonan
Copy link
Member

This was added with the latest ads-common release.

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

No branches or pull requests

5 participants