All of a sudden none of the client's authentication is success.

412 views
Skip to first unread message

Padmahas Bn

unread,
Aug 18, 2017, 7:49:45 AM8/18/17
to Google's DoubleClick for Publishers API Forum
Hello,

I'm using JSON approach for authenticating to DFP.
On 17 Aug, all of a sudden none of the Client's authentication is successful. I'm getting "OAuthException: Credential could not be refreshed" near .generateCredential()
But when I Googled out, I got a feeling this Exception will occur only when we use "ClientID and ClientSecret" approach and the "code" to generate refresh token or the current Refresh token is expired (I'm not sure, which one is the exact reason).

Credential oAuth2Credential = new OfflineCredentials.Builder()
       
.forApi(Api.DFP)
       
.fromFile()
       
.build()

       
.generateCredential(); // Exception occurred here

Below is the complete error.

Exception in thread "main" com.google.api.ads.common.lib.exception.OAuthException: Credential could not be refreshed.
    at com.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:178)
    at dfp.axis.v201702.companyservice.GetAdvertisers.main(GetAdvertisers.java:85)
Caused by: com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "invalid_grant",
  "error_description" : "Invalid JWT: Token must be a short-lived token and in a reasonable timeframe"
}
    at com.google.api.client.auth.oauth2.TokenResponseException.from(TokenResponseException.java:105)
    at com.google.api.client.auth.oauth2.TokenRequest.executeUnparsed(TokenRequest.java:287)
    at com.google.api.client.auth.oauth2.TokenRequest.execute(TokenRequest.java:307)
    at com.google.api.client.googleapis.auth.oauth2.GoogleCredential.executeRefreshToken(GoogleCredential.java:384)
    at com.google.api.client.auth.oauth2.Credential.refreshToken(Credential.java:489)
    at com.google.api.ads.common.lib.auth.OAuth2Helper.callRefreshToken(OAuth2Helper.java:69)
    at com.google.api.ads.common.lib.auth.OfflineCredentials.generateCredential(OfflineCredentials.java:172)
    ... 1 more

Thank you.

Nicholas Figeac (DFP API Team)

unread,
Aug 18, 2017, 1:43:54 PM8/18/17
to Google's DoubleClick for Publishers API Forum
Hello,

Are you using a service account? If so, can you send me the account email id and network code so I can verify? You can replay privately to author while sharing details. Service accounts should not use client id/secret, refresh tokens, or expire. 

A few things to check:
- The ads.properties file to make sure nothing was enabled for client id/secret implementation.
- Correct credentials are being used. 
- Your servers clock did not get out of sync with network time protocol. 

If issues are still persisting, you can try regenerating a new service account key. Instructions can be found here.

Thanks,
Nicholas Figeac, DFP API Team

Padmahas Bn

unread,
Aug 18, 2017, 3:11:18 PM8/18/17
to Google's DoubleClick for Publishers API Forum
Hello Nicholas,

Yes, I'm using the service account and I even tried with new JSON file. Even that failed. But when I checked again in the evening at about 5:30, it was working fine in my local system and other servers with old JSON itself.

While I was getting error,

The ads.properties file to make sure nothing was enabled for client id/secret implementation.
Surely nothing else other than jsonkeyfile, appname and networkcode was enabled.
Correct credentials are being used.
I'm sure I was using correct cred's.

Your servers clock did not get out of sync with network time protocol.
I'm not sure about this and also don't know how to check that.

Even now I'm not sure why it was giving refresh token related error for JSON approach.

Thank you.

Nicholas Figeac (DFP API Team)

unread,
Aug 21, 2017, 11:06:05 AM8/21/17
to Google's DoubleClick for Publishers API Forum
Hello,

I was able to verify the specific service account is active for your network. Is everything back to normal now with the old JSON file?

Padmahas Bn

unread,
Aug 21, 2017, 12:36:27 PM8/21/17
to Google's DoubleClick for Publishers API Forum
Yeah Nicholas,

Is everything back to normal now with the old JSON file?

Everything is back to normal now

Thank you.

Padmahas Bn

unread,
Aug 31, 2017, 10:39:06 AM8/31/17
to Google's DoubleClick for Publishers API Forum

Hey Nicholas,

I'm getting "Credential could not be refreshed" error while I'm trying to debug the sample code in STS 3.9.0. However I've not given any timeout time.
One more weird thing is, when I simply run the sample code without debugging, I didn't get any error. So I thought of running our REST endpoints which we have converted from the sample code without debugging, but new kind of error occurred as shown below.

"2017-08-31 19:13:18 - DispatcherServlet with name 'dispatcherServlet' processing POST request for [/theorem/ca/getAllAdUnitsBySize]
" "2017-08-31 19:13:18 - Looking up handler method for path /theorem/ca/getAllAdUnitsBySize
" "2017-08-31 19:13:18 - Returning handler method [public java.util.List<com.theorem.ca.dfp.bean.AdUnits> com.theorem.ca.dfp.controller.InventoryRestController.getAllAdUnitsFilteredBySize(com.theorem.ca.bean.FilterAdUnitsBean,javax.servlet.http.HttpServletRequest)]
" "2017-08-31 19:13:18 - Read [class com.theorem.ca.bean.FilterAdUnitsBean] as "application/json;charset=UTF-8" with [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@58df431e]
" "2017-08-31 19:13:21 - Resolving exception from handler [public java.util.List<com.theorem.ca.dfp.bean.AdUnits> com.theorem.ca.dfp.controller.InventoryRestController.getAllAdUnitsFilteredBySize(com.theorem.ca.bean.FilterAdUnitsBean,javax.servlet.http.HttpServletRequest)]: com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) null returned by binding at com.google.api.ads.common.lib.factory.FactoryModule$AdsServiceClientFactoryInterface.create()
 but parameter 2 of com.google.api.ads.dfp.lib.client.DfpServiceClient.<init>() is not @Nullable
  while locating com.google.api.ads.dfp.lib.client.DfpSession annotated with @com.google.inject.assistedinject.Assisted(value=adsSession)
    for parameter 2 at com.google.api.ads.dfp.lib.client.DfpServiceClient.<init>(DfpServiceClient.java:56)
  while locating com.google.api.ads.dfp.lib.client.DfpServiceClient annotated with @com.google.inject.internal.UniqueAnnotations$Internal(value=1)

1 error
" "2017-08-31 19:13:21 - Invoking @ExceptionHandler method: public com.theorem.ca.exception.ErrorInfo com.theorem.ca.exception.CustomExceptionHandlerAdvice.handleOtherException(java.lang.Exception)
" "2017-08-31 19:13:21 - Unhandled exception
" com.google.inject.ProvisionException: Unable to provision, see the following errors:

1) null returned by binding at com.google.api.ads.common.lib.factory.FactoryModule$AdsServiceClientFactoryInterface.create()
 but parameter 2 of com.google.api.ads.dfp.lib.client.DfpServiceClient.<init>() is not @Nullable
  while locating com.google.api.ads.dfp.lib.client.DfpSession annotated with @com.google.inject.assistedinject.Assisted(value=adsSession)
    for parameter 2 at com.google.api.ads.dfp.lib.client.DfpServiceClient.<init>(DfpServiceClient.java:56)
  while locating com.google.api.ads.dfp.lib.client.DfpServiceClient annotated with @com.google.inject.internal.UniqueAnnotations$Internal(value=1)

1 error
    at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1025) ~[guice-4.0.jar:?]
    at com.google.inject.assistedinject.FactoryProvider2.invoke(FactoryProvider2.java:770) ~[guice-assistedinject-4.0.jar:?]
    at com.sun.proxy.$Proxy187.create(Unknown Source) ~[?:?]
    at com.google.api.ads.common.lib.factory.helper.BaseAdsServiceClientFactoryHelper.createServiceClient(BaseAdsServiceClientFactoryHelper.java:86) ~[ads-lib-3.7.0.jar:?]
    at com.google.api.ads.common.lib.factory.helper.BaseAdsServiceClientFactoryHelper.createAdsServiceClient(BaseAdsServiceClientFactoryHelper.java:71) ~[ads-lib-3.7.0.jar:?]
    at com.google.api.ads.common.lib.factory.AdsServiceClientFactory.getServiceClient(AdsServiceClientFactory.java:76) ~[ads-lib-3.7.0.jar:?]
    at com.google.api.ads.common.lib.factory.BaseAdsServiceClientFactory.getServiceClientAsInterface(BaseAdsServiceClientFactory.java:81) ~[ads-lib-3.7.0.jar:?]
    at com.google.api.ads.common.lib.factory.BaseServices.get(BaseServices.java:45) ~[ads-lib-3.7.0.jar:?]
    at com.theorem.ca.dfp.service.impl.InventoryServiceImpl.getAllAdUnitsWithSizeFilterById(InventoryServiceImpl.java:251) ~[classes/:?]
    at com.theorem.ca.dfp.controller.InventoryRestController.getAllAdUnitsFilteredBySize(InventoryRestController.java:54) ~[classes/:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_144]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_144]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_144]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) [spring-webmvc-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) [tomcat-embed-websocket-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at com.theorem.ca.configuration.SimpleCORSFilter.doFilter(SimpleCORSFilter.java:45) [classes/:?]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:105) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:81) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:115) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.access$000(ErrorPageFilter.java:59) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:90) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.6.RELEASE.jar:4.3.6.RELEASE]
    at org.springframework.boot.web.support.ErrorPageFilter.doFilter(ErrorPageFilter.java:108) [spring-boot-1.5.1.RELEASE.jar:1.5.1.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:474) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1434) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_144]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_144]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.11.jar:8.5.11]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
"2017-08-31 19:13:21 - Written [com.theorem.ca.exception.ErrorInfo@7f638aba] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@58df431e]
" "2017-08-31 19:13:21 - Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling
" "2017-08-31 19:13:21 - Successfully completed request
"

How can I overcome this? I wouldn't have posted this here if, that exception was not thrown by DFP.

Thank you.

Gabe Rives-Corbett

unread,
Sep 1, 2017, 11:16:40 AM9/1/17
to Google's DoubleClick for Publishers API Forum
Hi,

I believe there's a problem with the way you're instantiating the DfpServices object. Can you please share your code that does this?

Thanks,
Gabe Rives-Corbett, DFP API Team
Reply all
Reply to author
Forward
0 new messages