Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email to GoogleUser #65

Merged
merged 1 commit into from
Nov 9, 2024

Conversation

doolle89
Copy link
Contributor

@doolle89 doolle89 commented Nov 1, 2024

Is it ok to retrieve email directly from idToken on client device?
As pointed out in this issue email is sometimes omitted from idToken but it seems it is mandatory field in GoogleIdTokenCredential so we can get it from there

@@ -73,7 +73,8 @@ internal class GoogleAuthUiProviderImpl(
GoogleUser(
idToken = googleIdTokenCredential.idToken,
accessToken = null,
displayName = googleIdTokenCredential.displayName ?: "",
email = googleIdTokenCredential.id,
displayName = googleIdTokenCredential.displayName,
Copy link
Owner

Choose a reason for hiding this comment

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

better to keep as it was before:
googleIdTokenCredential.displayName?:""

@@ -52,7 +52,8 @@ internal class GoogleLegacyAuthentication(
GoogleUser(
idToken = idToken,
accessToken = null,
displayName = account.displayName ?: "",
email = account.email,
displayName = account.displayName,
Copy link
Owner

Choose a reason for hiding this comment

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

better to keep as it was before:
account.displayName?:""

val displayName: String = "",
val accessToken:String? = null,
val email: String? = null,
val displayName: String? = null,
Copy link
Owner

Choose a reason for hiding this comment

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

don't want to break things with new update. So instead of nullable displayName, it should be non nullable as before,and should be set as empty string if it is null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok I see, I ll revert the update.
I think that you should consider this update when making major version increase because hiding nullability is not a good practice, with the current state it's not possible to distinguish the case when id token doesn't contain name from the case when user has actually an empty name. It's not a big difference but in general it's easier to let clients to handle nullability :)

Copy link
Owner

@mirzemehdi mirzemehdi Nov 2, 2024

Choose a reason for hiding this comment

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

yes, good point. For major update I'll keep this in my mind. Thank you for pointing out that @doolle89

@@ -27,7 +27,8 @@ internal class GoogleAuthUiProviderImpl : GoogleAuthUiProvider {
val googleUser = GoogleUser(
idToken = idToken,
accessToken = accessToken,
displayName = profile?.name ?: "",
email = user?.userID,
displayName = profile?.name,
Copy link
Owner

Choose a reason for hiding this comment

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

better to keep as it was before:
profile.name?:""

@@ -54,6 +54,7 @@ internal class GoogleAuthUiProviderImpl(private val credentials: GoogleAuthCrede
return null
}
val jwt = JWT().decodeJwt(idToken)
val email = jwt.getClaim("email")?.asString() // User's name
Copy link
Owner

Choose a reason for hiding this comment

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

comment part -> //user's email

@@ -65,7 +66,8 @@ internal class GoogleAuthUiProviderImpl(private val credentials: GoogleAuthCrede
return GoogleUser(
idToken = idToken,
accessToken = null,
displayName = name ?: "",
email = email,
displayName = name,
Copy link
Owner

Choose a reason for hiding this comment

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

should be kept as before name?:""

Copy link
Owner

@mirzemehdi mirzemehdi left a comment

Choose a reason for hiding this comment

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

Thank you very much @doolle89 for this PR. Looks good to me. Just requested minor changes related to displayName field as I don't want to break things for new api

@doolle89
Copy link
Contributor Author

doolle89 commented Nov 1, 2024

I updated points from the review... Just please test it if you can before merging, I can't test sample app, most probably because my keystore fingerprint is not matching the one in GPC

@mirzemehdi
Copy link
Owner

Thank you @doolle89 for changes. After testing I'll merge it

@mirzemehdi mirzemehdi changed the base branch from main to rel_v2.3.0 November 9, 2024 10:32
@mirzemehdi mirzemehdi merged commit 4cd753d into mirzemehdi:rel_v2.3.0 Nov 9, 2024
4 checks passed
@mirzemehdi
Copy link
Owner

Thanks again @doolle89 for this, just tested, and published new release. This will be available in 2.3.0-beta01 version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants