Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Ports/Android/src/com/codename1/social/GoogleImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
String displayName = acct.getDisplayName();
String acctId = acct.getId();
String email = acct.getEmail();
String requestIdToken = acct.getIdToken();
final String requestIdToken = acct.getIdToken();
Set<Scope> grantedScopes = acct.getGrantedScopes();
String code = acct.getServerAuthCode();
String scopeStr = scope;
Expand All @@ -133,7 +133,14 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
protected void readResponse(InputStream input) throws IOException {
Map<String, Object> json = new JSONParser().parseJSON(new InputStreamReader(input, "UTF-8"));
if (json.containsKey("access_token")) {
setAccessToken(new AccessToken((String) json.get("access_token"), (String)null));
String accessToken = (String) json.get("access_token");
String expiresIn = json.containsKey("expires_in") ? String.valueOf(json.get("expires_in")) : null;
String refreshToken = json.containsKey("refresh_token") ? (String) json.get("refresh_token") : null;
String idToken = json.containsKey("id_token") ? (String) json.get("id_token") : requestIdToken;

// Use the constructor that includes all token fields
setAccessToken(new AccessToken(accessToken, expiresIn, refreshToken, idToken));
Copy link

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code assumes a 4-parameter AccessToken constructor exists, but this may be a breaking change if the existing AccessToken class doesn't support this constructor signature. Consider verifying that the AccessToken class has been updated to support these parameters.

Suggested change
setAccessToken(new AccessToken(accessToken, expiresIn, refreshToken, idToken));
AccessToken token = new AccessToken(accessToken, expiresIn);
// Set refreshToken and idToken if setters are available
try {
java.lang.reflect.Method setRefreshToken = token.getClass().getMethod("setRefreshToken", String.class);
setRefreshToken.invoke(token, refreshToken);
} catch (Exception e) {
// Setter not available, ignore
}
try {
java.lang.reflect.Method setIdToken = token.getClass().getMethod("setIdToken", String.class);
setIdToken.invoke(token, idToken);
} catch (Exception e) {
// Setter not available, ignore
}
setAccessToken(token);

Copilot uses AI. Check for mistakes.

Display.getInstance().callSerially(new Runnable() {

@Override
Expand All @@ -142,7 +149,9 @@ public void run() {
}
});
} else {
setAccessToken(new AccessToken());
// Even if we don't get an access token from the server, we can still set the ID token
// that we received from the initial Google Sign-In
setAccessToken(new AccessToken(null, null, null, requestIdToken));
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.");
Log.p("Response was " + json);
Display.getInstance().callSerially(new Runnable() {
Expand All @@ -168,7 +177,8 @@ public void run() {
req.setReadResponseForErrors(true);
NetworkManager.getInstance().addToQueue(req);
} else {
setAccessToken(new AccessToken());
// Even without clientId and clientSecret, we should still preserve the ID token from the initial sign-in
setAccessToken(new AccessToken(null, null, null, requestIdToken));
Log.p("The access token was set to null because one of clientId, clientSecret, requestIdToken, or auth were null");
Log.p("The login succeeded, but you won't be able to make any requests to Google's REST apis using the login token.");
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" +
Expand Down