Skip to content

Commit 9ce9642

Browse files
authored
chore: update GAE Oauth2 sample (GoogleCloudPlatform#7352)
1 parent 3f790b3 commit 9ce9642

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

appengine-java11/oauth2/pom.xml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,35 @@
4646
<!-- `java-docs-samples/appengine-java11/appengine-simple-jetty-main' -->
4747
<!-- See the README for more information -->
4848
<dependency>
49-
<groupId>com.example.appengine.demo</groupId>
50-
<artifactId>simple-jetty-main</artifactId>
51-
<version>1</version>
52-
<scope>provided</scope>
49+
<groupId>com.example.appengine.demo</groupId>
50+
<artifactId>simple-jetty-main</artifactId>
51+
<version>1</version>
52+
<scope>provided</scope>
5353
</dependency>
5454

5555
<!-- OAuth 2.0 packages -->
5656
<!-- [START gae_java11_oauth2_dependencies] -->
5757
<dependency>
5858
<groupId>com.google.oauth-client</groupId>
5959
<artifactId>google-oauth-client</artifactId>
60-
<version>1.33.3</version>
60+
<version>1.34.1</version>
6161
<scope>provided</scope>
6262
</dependency>
6363

6464
<dependency>
6565
<groupId>com.google.oauth-client</groupId>
6666
<artifactId>google-oauth-client-servlet</artifactId>
67-
<version>1.33.3</version>
67+
<version>1.34.1</version>
6868
<scope>provided</scope>
6969
</dependency>
7070

7171
<dependency>
7272
<groupId>com.google.apis</groupId>
7373
<artifactId>google-api-services-oauth2</artifactId>
74-
<version>v2-rev20200213-1.32.1</version>
74+
<version>v2-rev20200213-2.0.0</version>
7575
<scope>provided</scope>
7676
</dependency>
77-
<dependency>
78-
<groupId>com.google.http-client</groupId>
79-
<artifactId>google-http-client-jackson2</artifactId>
80-
<version>1.41.8</version>
81-
</dependency>
77+
8278
<!-- [END gae_java11_oauth2_dependencies] -->
8379

8480
<dependency>

appengine-java11/oauth2/src/main/appengine/app.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ env_variables:
2020
CLIENT_ID: '<YOUR_CLIENT_ID>'
2121
CLIENT_SECRET: '<YOUR_CLIENT_SECRET>'
2222
# [END gae_java11_oauth2_yaml]
23+
handlers:
24+
- url: /.*
25+
secure: always
26+
redirect_http_response_code: 301
27+
script: auto

appengine-java11/oauth2/src/main/java/com/example/appengine/Utils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import com.google.api.client.http.HttpTransport;
2323
import com.google.api.client.http.javanet.NetHttpTransport;
2424
import com.google.api.client.json.JsonFactory;
25-
import com.google.api.client.json.jackson2.JacksonFactory;
25+
import com.google.api.client.json.gson.GsonFactory;
2626
import com.google.api.client.util.store.MemoryDataStoreFactory;
2727
import com.google.api.services.oauth2.Oauth2;
2828
import com.google.api.services.oauth2.model.Userinfo;
@@ -48,7 +48,7 @@ public class Utils {
4848
static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
4949

5050
/** Global instance of the JSON factory. */
51-
static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
51+
static final GsonFactory JSON_FACTORY = new GsonFactory();
5252

5353
/** Set your OAuth 2.0 Client Credentials */
5454
private static String CLIENT_ID = System.getenv("CLIENT_ID");
@@ -65,6 +65,7 @@ public class Utils {
6565
static String getRedirectUri(HttpServletRequest req) {
6666
GenericUrl url = new GenericUrl(req.getRequestURL().toString());
6767
url.setRawPath("/oauth2callback");
68+
url.setScheme("https");
6869
return url.build();
6970
}
7071

@@ -77,7 +78,6 @@ public static GoogleAuthorizationCodeFlow newFlow() throws IOException {
7778
return new GoogleAuthorizationCodeFlow.Builder(
7879
HTTP_TRANSPORT, JSON_FACTORY, CLIENT_ID, CLIENT_SECRET, SCOPES)
7980
.setDataStoreFactory(DATA_STORE_FACTORY)
80-
.setAccessType("offline")
8181
.build();
8282
}
8383
// [END gae_java11_oauth2_code_flow]

0 commit comments

Comments
 (0)