Thursday, October 17, 2013

Re: How do I refresh the OAuth Token when using Google Cloud SQL JDBC Driver?

The ones in the doc are the ones you should use.

Rob

On Thursday, October 17, 2013, Alexander Bertram wrote:
I've tried using the clientId / secret (0000000000@project.googleusercontent.com) from the service account listed on the API console, but then I get this error:

Caused by: com.google.cloud.sql.jdbc.internal.googleapi.RefreshTokenAccessTokenRefresher$OAuth2AuthorizationException: 400 Bad Request
{
  "error" : "invalid_client"
}
at com.google.cloud.sql.jdbc.internal.googleapi.RefreshTokenAccessTokenRefresher.refreshAccessToken(RefreshTokenAccessTokenRefresher.java:49)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi$DefaultGoogleApi.refreshAccessToken(RpcGoogleApi.java:314)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi$DefaultGoogleApi.refreshAccessTokenIfNeeded(RpcGoogleApi.java:419)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi$DefaultGoogleApi.exec(RpcGoogleApi.java:301)
at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:99)

What clientId should I be using? 

Alex

On Thursday, October 17, 2013 3:35:15 PM UTC+2, Rob wrote:
The driver should do it already.

Are you setting the OAuth2 properties (client id and secret) in code as mentioned here: 

Rob



On Thu, Oct 17, 2013 at 12:34 AM, Alexander Bertram <al...@bedatadriven.com> wrote:

I am using the Google Cloud SQL driver on a Google Compute Instance to persist results to a Google Cloud SQL database during a long running batch process.

At some point, perhaps after the first hour of running, the oAuth token seems to expire, and all subsequent requests fail with:

  Caused by: java.sql.SQLException: 400 Bad Request  {     "error" : "unauthorized_client"  }  at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.newOpenConnectionIOException(RpcGoogleApi.java:168)  at com.google.cloud.sql.jdbc.internal.googleapi.RpcGoogleApi.openConnection(RpcGoogleApi.java:104)  at com.google.cloud.sql.jdbc.internal.SqlProtoClient.openConnection(SqlProtoClient.java:58)  at com.google.cloud.sql.jdbc.Driver.connect(Driver.java:66)  at com.google.cloud.sql.Driver.connectImpl(Driver.java:109)  at com.google.cloud.sql.Driver.connect(Driver.java:98)  at com.google.cloud.sql.Driver.connect(Driver.java:31)  

I can abort the process, run google_sql.sh from the client line and the restart the batch process, and the connection will be fine until the token expires again.

Apparently, the command line tool is doing something to refresh the token before connecting; how do I do the same for my batch process?

Looking at the google_sql jar, it seems that it using the Google API Client library under the hood; is there a way to control this process more explicitly?

Thanks,

Alex

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/bbf71d3a-ff2b-4304-9f02-0584383c1408%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/e3a7b5d7-8db8-4d71-8546-204efc6bdaa9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/CA%2BbE6i3R37BEzKmHa8HoyUbtzHYTjOB5soELLY5QYqt_5qc%2B1g%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment