@@ -113,7 +113,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
113113 String displayName = acct .getDisplayName ();
114114 String acctId = acct .getId ();
115115 String email = acct .getEmail ();
116- String requestIdToken = acct .getIdToken ();
116+ final String requestIdToken = acct .getIdToken ();
117117 Set <Scope > grantedScopes = acct .getGrantedScopes ();
118118 String code = acct .getServerAuthCode ();
119119 String scopeStr = scope ;
@@ -133,7 +133,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
133133 protected void readResponse (InputStream input ) throws IOException {
134134 Map <String , Object > json = new JSONParser ().parseJSON (new InputStreamReader (input , "UTF-8" ));
135135 if (json .containsKey ("access_token" )) {
136- setAccessToken (new AccessToken ((String ) json .get ("access_token" ), (String )null ));
136+ String accessToken = (String ) json .get ("access_token" );
137+ String expiresIn = json .containsKey ("expires_in" ) ? String .valueOf (json .get ("expires_in" )) : null ;
138+ String refreshToken = json .containsKey ("refresh_token" ) ? (String ) json .get ("refresh_token" ) : null ;
139+ String idToken = json .containsKey ("id_token" ) ? (String ) json .get ("id_token" ) : requestIdToken ;
140+
141+ // Use the constructor that includes all token fields
142+ setAccessToken (new AccessToken (accessToken , expiresIn , refreshToken , idToken ));
143+
137144 Display .getInstance ().callSerially (new Runnable () {
138145
139146 @ Override
@@ -142,7 +149,9 @@ public void run() {
142149 }
143150 });
144151 } else {
145- setAccessToken (new AccessToken ());
152+ // Even if we don't get an access token from the server, we can still set the ID token
153+ // that we received from the initial Google Sign-In
154+ setAccessToken (new AccessToken (null , null , null , requestIdToken ));
146155 Log .p ("Failed to retrieve the access token from the google auth server. Login succeeded, but access token is null, so you won't be able to use it to retrieve additional information." );
147156 Log .p ("Response was " + json );
148157 Display .getInstance ().callSerially (new Runnable () {
@@ -168,7 +177,8 @@ public void run() {
168177 req .setReadResponseForErrors (true );
169178 NetworkManager .getInstance ().addToQueue (req );
170179 } else {
171- setAccessToken (new AccessToken ());
180+ // Even without clientId and clientSecret, we should still preserve the ID token from the initial sign-in
181+ setAccessToken (new AccessToken (null , null , null , requestIdToken ));
172182 Log .p ("The access token was set to null because one of clientId, clientSecret, requestIdToken, or auth were null" );
173183 Log .p ("The login succeeded, but you won't be able to make any requests to Google's REST apis using the login token." );
174184 Log .p ("In order to obtain a token that can be used with Google's REST APIs, you need to set the clientId, and clientSecret of" +
0 commit comments