From 6abfe3d418363cb89d30db58c8eb65a1e0645ae4 Mon Sep 17 00:00:00 2001 From: Eyal Peled Date: Thu, 22 Aug 2013 10:08:11 -0400 Subject: [PATCH 1/5] branch wow From 211570194bc51f09a428fe6646d04bcc39204030 Mon Sep 17 00:00:00 2001 From: Nick Miceli Date: Fri, 23 Aug 2013 10:00:52 -0400 Subject: [PATCH 2/5] api: Added GoogleAppEngineOAuthApplicationContext, ServiceFactory --- ...oogleAppEngineOAuthApplicationContext.java | 66 ++++++++++++++++++ .../appengine/utils/ServiceFactory.java | 67 +++++++++++++++++++ .../appengine/utils/package-info.java | 23 +++++++ 3 files changed, 156 insertions(+) create mode 100644 google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java create mode 100644 google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java create mode 100644 google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/package-info.java diff --git a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java new file mode 100644 index 00000000..67f48bf4 --- /dev/null +++ b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.api.client.googleapis.extensions.appengine.auth.oauth2; + +import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; +import com.google.api.client.extensions.appengine.auth.oauth2.AppEngineOAuthApplicationContext; +import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; +import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Collection; +import java.util.concurrent.locks.ReentrantLock; + +/** + * @author ngmiceli@google.com (Your Name Here) + * + */ +public class GoogleAppEngineOAuthApplicationContext extends AppEngineOAuthApplicationContext { + + private AuthorizationCodeFlow flow; + private GoogleClientSecrets clientSecrets; + private String clientSecretsPath; + private ReentrantLock lock = new ReentrantLock(); + + public GoogleAppEngineOAuthApplicationContext(String redirectUri, String clientSecretsPath, + Collection scopes, String applicationName) { + super(redirectUri, scopes, applicationName); + this.clientSecretsPath = clientSecretsPath; + } + + protected GoogleClientSecrets getClientSecrets() throws IOException { + if (clientSecrets == null) { + clientSecrets = GoogleClientSecrets.load(getJsonFactory(), new InputStreamReader( + GoogleAppEngineOAuthApplicationContext.class.getResourceAsStream(clientSecretsPath))); + } + return clientSecrets; + } + + @Override // TODO(NOW): Lock / thread-safety + public AuthorizationCodeFlow getFlow() throws IOException { + if (flow == null) { + try { + lock.lock(); + flow = new GoogleAuthorizationCodeFlow.Builder(getTransport(), getJsonFactory(), + getClientSecrets(), getScopes()).setDataStoreFactory(getDataStoreFactory()) + .setAccessType("offline").build(); + } finally { + lock.unlock(); + } + } + return flow; + } +} diff --git a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java new file mode 100644 index 00000000..2e288afe --- /dev/null +++ b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.api.client.googleapis.extensions.appengine.utils; + +import com.google.api.client.auth.oauth2.Credential; +import com.google.api.client.auth.oauth2.OAuthApplicationContext; +import com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient; +import com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient.Builder; +import com.google.api.client.http.HttpRequestInitializer; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.appengine.api.users.UserServiceFactory; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +/** + * @author ngmiceli@google.com (Your Name Here) + * + */ +public class ServiceFactory { + + public static T createService( + Class service, OAuthApplicationContext context) + throws IOException { + for (Class builderClass : service.getDeclaredClasses()) { + if (AbstractGoogleJsonClient.Builder.class.isAssignableFrom(builderClass)) { + try { + Constructor constructor = builderClass.getConstructor( + HttpTransport.class, JsonFactory.class, HttpRequestInitializer.class); + Credential credential = context.getFlow() + .loadCredential(UserServiceFactory.getUserService().getCurrentUser().getUserId()); + // TODO(NOW): Do we want to allow the user to pass their own HttpRequestInitializer? + AbstractGoogleJsonClient.Builder builder = (Builder) constructor.newInstance( + context.getTransport(), context.getJsonFactory(), credential); + builder.setApplicationName(context.getApplicationName()); + @SuppressWarnings("unchecked") + T t = (T) builder.build(); + return t; + } catch (ClassCastException exception) { + } catch (NoSuchMethodException exception) { + } catch (SecurityException exception) { + } catch (InstantiationException exception) { + } catch (IllegalAccessException exception) { + } catch (IllegalArgumentException exception) { + } catch (InvocationTargetException exception) { + } + } + } + // TODO(NOW): Figure out the right way to handle all these exceptions. + throw new IllegalArgumentException(); + } + +} diff --git a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/package-info.java b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/package-info.java new file mode 100644 index 00000000..dd4e1c8a --- /dev/null +++ b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * Stuff + * + * @since 1.17 + * @author Nick Miceli + */ + +package com.google.api.client.googleapis.extensions.appengine.utils; + From eba3b8a9bbc37f34e451d3e3e5692383340d4e65 Mon Sep 17 00:00:00 2001 From: Eyal Peled Date: Fri, 6 Sep 2013 12:59:00 -0400 Subject: [PATCH 3/5] Add GoogleOAuthInstalledAppContext --- ...oogleAppEngineOAuthApplicationContext.java | 35 +++-- .../GoogleOAuthInstalledAppContext.java | 121 ++++++++++++++++++ .../jackson2/auth/oauth2/package-info.java | 25 ++++ .../auth/oauth2/GoogleClientSecrets.java | 13 +- 4 files changed, 182 insertions(+), 12 deletions(-) create mode 100644 google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java create mode 100644 google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/package-info.java diff --git a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java index 67f48bf4..5d88ffd9 100644 --- a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java +++ b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java @@ -25,15 +25,23 @@ import java.util.concurrent.locks.ReentrantLock; /** - * @author ngmiceli@google.com (Your Name Here) + * Thread safe OAuth 2.0 authorization appengine application context. It extends + * {@link AppEngineOAuthApplicationContext} and add implementation for both + * {@link #getClientSecrets} and {@link #getFlow}. + * + * @author Nick Miceli + * @author Eyal Peled + * + * @since 1.18 * */ public class GoogleAppEngineOAuthApplicationContext extends AppEngineOAuthApplicationContext { private AuthorizationCodeFlow flow; private GoogleClientSecrets clientSecrets; - private String clientSecretsPath; - private ReentrantLock lock = new ReentrantLock(); + + private final String clientSecretsPath; + private final ReentrantLock lock = new ReentrantLock(); public GoogleAppEngineOAuthApplicationContext(String redirectUri, String clientSecretsPath, Collection scopes, String applicationName) { @@ -42,24 +50,29 @@ public GoogleAppEngineOAuthApplicationContext(String redirectUri, String clientS } protected GoogleClientSecrets getClientSecrets() throws IOException { - if (clientSecrets == null) { - clientSecrets = GoogleClientSecrets.load(getJsonFactory(), new InputStreamReader( - GoogleAppEngineOAuthApplicationContext.class.getResourceAsStream(clientSecretsPath))); + lock.lock(); + try { + if (clientSecrets == null) { + clientSecrets = GoogleClientSecrets.load(getJsonFactory(), new InputStreamReader( + GoogleAppEngineOAuthApplicationContext.class.getResourceAsStream(clientSecretsPath))); + } + } finally { + lock.unlock(); } return clientSecrets; } @Override // TODO(NOW): Lock / thread-safety public AuthorizationCodeFlow getFlow() throws IOException { - if (flow == null) { - try { - lock.lock(); + lock.lock(); + try { + if (flow == null) { flow = new GoogleAuthorizationCodeFlow.Builder(getTransport(), getJsonFactory(), getClientSecrets(), getScopes()).setDataStoreFactory(getDataStoreFactory()) .setAccessType("offline").build(); - } finally { - lock.unlock(); } + } finally { + lock.unlock(); } return flow; } diff --git a/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java new file mode 100644 index 00000000..47b1581e --- /dev/null +++ b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package com.google.api.client.googleapis.extensions.jackson2.auth.oauth2; + +import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; +import com.google.api.client.auth.oauth2.OAuthApplicationContext; +import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; +import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; +import com.google.api.client.http.HttpTransport; +import com.google.api.client.http.javanet.NetHttpTransport; +import com.google.api.client.json.JsonFactory; +import com.google.api.client.json.jackson2.JacksonFactory; +import com.google.api.client.util.store.DataStoreFactory; +import com.google.api.client.util.store.FileDataStoreFactory; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Collection; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Thread safe OAuth 2.0 authorization context for installed application. It implements + * {@link OAuthApplicationContext} with default values such as + * {@link NetHttpTransport#getDefaultInstance} as the HTTP transport and + * {@link JacksonFactory#getDefaultInstance} as the JSON factory. + * + * @author Nick Miceli + * @author Eyal Peled + * + * @since 1.18 + */ +public class GoogleOAuthInstalledAppContext implements OAuthApplicationContext { + private AuthorizationCodeFlow flow; + private GoogleClientSecrets clientSecrets; + private DataStoreFactory dataStoreFactory; + + private final String clientSecretsPath; + private final Collection scopes; + private final String applicationName; + + private final ReentrantLock lock = new ReentrantLock(); + + + public GoogleOAuthInstalledAppContext( + String clientSecretsPath, Collection scopes, String applicationName) { + try { + dataStoreFactory = new FileDataStoreFactory( + new java.io.File(System.getProperty("user.home"), ".store/" + applicationName)); + } catch (IOException exception) { + System.exit(1); + } + this.clientSecretsPath = clientSecretsPath; + this.applicationName = applicationName; + this.scopes = scopes; + } + + @Override + public HttpTransport getTransport() { + return NetHttpTransport.getDefaultInstance(); + } + + @Override + public JsonFactory getJsonFactory() { + return JacksonFactory.getDefaultInstance(); + } + + @Override // TODO(NOW): Lock / thread-safety + public AuthorizationCodeFlow getFlow() throws IOException { + lock.lock(); + try { + if (flow == null) { + flow = new GoogleAuthorizationCodeFlow.Builder(getTransport(), getJsonFactory(), + getClientSecrets(), getScopes()).setDataStoreFactory(getDataStoreFactory()) + .setAccessType("offline").build(); + } + } finally { + lock.unlock(); + } + return flow; + } + + @Override + public DataStoreFactory getDataStoreFactory() { + return dataStoreFactory; + } + + @Override + public String getApplicationName() { + return applicationName; + } + + @Override + public Collection getScopes() { + return scopes; + } + + protected GoogleClientSecrets getClientSecrets() throws IOException { + lock.lock(); + try { + if (clientSecrets == null) { + clientSecrets = GoogleClientSecrets.load(getJsonFactory(), new InputStreamReader( + GoogleOAuthInstalledAppContext.class.getResourceAsStream(clientSecretsPath))); + } + } finally { + lock.unlock(); + } + return clientSecrets; + } +} diff --git a/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/package-info.java b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/package-info.java new file mode 100644 index 00000000..242f5220 --- /dev/null +++ b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/package-info.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2013 Google Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +/** + * {@link com.google.api.client.util.Beta}
+ * OAuth 2.0 utilities that help simplify the authorization flow on Google installed applications. + * + * @author Nick Miceli + * @author Eyal Peled + * @since 1.18 + */ +@com.google.api.client.util.Beta +package com.google.api.client.googleapis.extensions.jackson2.auth.oauth2; + diff --git a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleClientSecrets.java b/google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleClientSecrets.java index 4b42b4ff..d8e11af5 100644 --- a/google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleClientSecrets.java +++ b/google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleClientSecrets.java @@ -183,10 +183,21 @@ public GoogleClientSecrets clone() { /** * Loads the {@code client_secrets.json} file from the given reader. * + *

+ * Upgrade warning: in prior version 1.17 {@link #load} didn't throw + * {@link IllegalArgumentException} in case the client id or the client secret started with + * 'Enter', but starting with version 1.18 it will throw {@link IllegalArgumentException}. + *

+ * * @since 1.15 */ public static GoogleClientSecrets load(JsonFactory jsonFactory, Reader reader) throws IOException { - return jsonFactory.fromReader(reader, GoogleClientSecrets.class); + GoogleClientSecrets clientSecrets = jsonFactory.fromReader(reader, GoogleClientSecrets.class); + Preconditions.checkArgument(!clientSecrets.getDetails().getClientId().startsWith("Enter ") + && !clientSecrets.getDetails().getClientSecret().startsWith("Enter "), + "Download client_secrets.json file from https://code.google.com/apis/console/" + + " into your resources folder."); + return clientSecrets; } } From 2f798ba92b40903200a1007cc1727704994139b5 Mon Sep 17 00:00:00 2001 From: Eyal Peled Date: Wed, 11 Sep 2013 12:02:21 -0400 Subject: [PATCH 4/5] change GoogleOAuthInstalledAppContext constructor to throw exception --- .../GoogleOAuthInstalledAppContext.java | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java index 47b1581e..1beba044 100644 --- a/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java +++ b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java @@ -42,25 +42,29 @@ * @since 1.18 */ public class GoogleOAuthInstalledAppContext implements OAuthApplicationContext { + private AuthorizationCodeFlow flow; private GoogleClientSecrets clientSecrets; - private DataStoreFactory dataStoreFactory; + private final DataStoreFactory dataStoreFactory; private final String clientSecretsPath; private final Collection scopes; private final String applicationName; private final ReentrantLock lock = new ReentrantLock(); - + /** + * Constructs a new OAuth context for installed applications. + * + * @param clientSecretsPath path to the client secrets Json file + * @param scopes scopes + * @param applicationName application name + */ public GoogleOAuthInstalledAppContext( - String clientSecretsPath, Collection scopes, String applicationName) { - try { - dataStoreFactory = new FileDataStoreFactory( - new java.io.File(System.getProperty("user.home"), ".store/" + applicationName)); - } catch (IOException exception) { - System.exit(1); - } + String clientSecretsPath, Collection scopes, String applicationName) + throws IOException { + dataStoreFactory = new FileDataStoreFactory( + new java.io.File(System.getProperty("user.home"), ".store/" + applicationName)); this.clientSecretsPath = clientSecretsPath; this.applicationName = applicationName; this.scopes = scopes; @@ -76,7 +80,7 @@ public JsonFactory getJsonFactory() { return JacksonFactory.getDefaultInstance(); } - @Override // TODO(NOW): Lock / thread-safety + @Override public AuthorizationCodeFlow getFlow() throws IOException { lock.lock(); try { @@ -106,6 +110,9 @@ public Collection getScopes() { return scopes; } + /** + * Returns the Google client secrets which contains the client identifier and client secret + */ protected GoogleClientSecrets getClientSecrets() throws IOException { lock.lock(); try { From f57ed64030f4c896d2f8273a68c52c3fdc5473af Mon Sep 17 00:00:00 2001 From: Eyal Peled Date: Wed, 18 Sep 2013 16:01:49 -0400 Subject: [PATCH 5/5] doc --- .../oauth2/GoogleAppEngineOAuthApplicationContext.java | 6 +++--- .../extensions/appengine/utils/ServiceFactory.java | 6 +++--- .../auth/oauth2/GoogleOAuthInstalledAppContext.java | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java index 5d88ffd9..4170ae0c 100644 --- a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java +++ b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/auth/oauth2/GoogleAppEngineOAuthApplicationContext.java @@ -15,7 +15,7 @@ package com.google.api.client.googleapis.extensions.appengine.auth.oauth2; import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; -import com.google.api.client.extensions.appengine.auth.oauth2.AppEngineOAuthApplicationContext; +import com.google.api.client.extensions.appengine.auth.oauth2.AppEngineOAuthContext; import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; @@ -26,7 +26,7 @@ /** * Thread safe OAuth 2.0 authorization appengine application context. It extends - * {@link AppEngineOAuthApplicationContext} and add implementation for both + * {@link AppEngineOAuthContext} and add implementation for both * {@link #getClientSecrets} and {@link #getFlow}. * * @author Nick Miceli @@ -35,7 +35,7 @@ * @since 1.18 * */ -public class GoogleAppEngineOAuthApplicationContext extends AppEngineOAuthApplicationContext { +public class GoogleAppEngineOAuthApplicationContext extends AppEngineOAuthContext { private AuthorizationCodeFlow flow; private GoogleClientSecrets clientSecrets; diff --git a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java index 2e288afe..cb77c4ec 100644 --- a/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java +++ b/google-api-client-appengine/src/main/java/com/google/api/client/googleapis/extensions/appengine/utils/ServiceFactory.java @@ -15,7 +15,7 @@ package com.google.api.client.googleapis.extensions.appengine.utils; import com.google.api.client.auth.oauth2.Credential; -import com.google.api.client.auth.oauth2.OAuthApplicationContext; +import com.google.api.client.auth.oauth2.OAuthContext; import com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient; import com.google.api.client.googleapis.services.json.AbstractGoogleJsonClient.Builder; import com.google.api.client.http.HttpRequestInitializer; @@ -34,7 +34,7 @@ public class ServiceFactory { public static T createService( - Class service, OAuthApplicationContext context) + Class service, OAuthContext context) throws IOException { for (Class builderClass : service.getDeclaredClasses()) { if (AbstractGoogleJsonClient.Builder.class.isAssignableFrom(builderClass)) { @@ -46,7 +46,7 @@ public static T createService( // TODO(NOW): Do we want to allow the user to pass their own HttpRequestInitializer? AbstractGoogleJsonClient.Builder builder = (Builder) constructor.newInstance( context.getTransport(), context.getJsonFactory(), credential); - builder.setApplicationName(context.getApplicationName()); + builder.setApplicationName(context.getUserAgent()); @SuppressWarnings("unchecked") T t = (T) builder.build(); return t; diff --git a/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java index 1beba044..90d50a9b 100644 --- a/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java +++ b/google-api-client-jackson2/src/main/java/com/google/api/client/googleapis/extensions/jackson2/auth/oauth2/GoogleOAuthInstalledAppContext.java @@ -15,7 +15,7 @@ package com.google.api.client.googleapis.extensions.jackson2.auth.oauth2; import com.google.api.client.auth.oauth2.AuthorizationCodeFlow; -import com.google.api.client.auth.oauth2.OAuthApplicationContext; +import com.google.api.client.auth.oauth2.OAuthContext; import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; import com.google.api.client.http.HttpTransport; @@ -32,7 +32,7 @@ /** * Thread safe OAuth 2.0 authorization context for installed application. It implements - * {@link OAuthApplicationContext} with default values such as + * {@link OAuthContext} with default values such as * {@link NetHttpTransport#getDefaultInstance} as the HTTP transport and * {@link JacksonFactory#getDefaultInstance} as the JSON factory. * @@ -41,7 +41,7 @@ * * @since 1.18 */ -public class GoogleOAuthInstalledAppContext implements OAuthApplicationContext { +public class GoogleOAuthInstalledAppContext implements OAuthContext { private AuthorizationCodeFlow flow; private GoogleClientSecrets clientSecrets; @@ -101,7 +101,7 @@ public DataStoreFactory getDataStoreFactory() { } @Override - public String getApplicationName() { + public String getUserAgent() { return applicationName; }