Skip to content
This repository has been archived by the owner on Sep 12, 2021. It is now read-only.

Commit

Permalink
GoogleProvider: Suppress Google's default profile picture (#540)
Browse files Browse the repository at this point in the history
  • Loading branch information
mheuer authored and akkie committed Apr 18, 2018
1 parent 30bc607 commit d0b3618
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 1 deletion.
Expand Up @@ -92,6 +92,7 @@ class GoogleProfileParser extends SocialProfileParser[JsValue, CommonSocialProfi
val lastName = (json \ "name" \ "familyName").asOpt[String]
val fullName = (json \ "displayName").asOpt[String]
val avatarURL = (json \ "image" \ "url").asOpt[String]
val isDefaultAvatar = (json \ "image" \ "isDefault").asOpt[Boolean].getOrElse(false)

// https://developers.google.com/+/api/latest/people#emails.type
val emailIndex = (json \ "emails" \\ "type").indexWhere(_.as[String] == "account")
Expand All @@ -106,7 +107,7 @@ class GoogleProfileParser extends SocialProfileParser[JsValue, CommonSocialProfi
firstName = firstName,
lastName = lastName,
fullName = fullName,
avatarURL = avatarURL,
avatarURL = if (isDefaultAvatar) None else avatarURL, // skip the default avatar picture
email = emailValue)
}
}
Expand Down
Expand Up @@ -197,6 +197,44 @@ class GoogleProviderSpec extends OAuth2ProviderSpec {
)
}
}
"return the social profile with an avatar url" in new WithApplication with Context {
val wsRequest = mock[MockWSRequest]
val wsResponse = mock[MockWSRequest#Response]
wsResponse.status returns 200
wsResponse.json returns Helper.loadJson("providers/oauth2/google.img.non-default.json")
wsRequest.get() returns Future.successful(wsResponse)
httpLayer.url(API.format("my.access.token")) returns wsRequest

profile(provider.retrieveProfile(oAuthInfo.as[OAuth2Info])) { p =>
p must be equalTo CommonSocialProfile(
loginInfo = LoginInfo(provider.id, "109476598527568979481"),
firstName = Some("Apollonia"),
lastName = Some("Vanova"),
fullName = Some("Apollonia Vanova"),
email = Some("apollonia.vanova@watchmen.com"),
avatarURL = Some("https://lh6.googleusercontent.com/-m34A6I77dJU/ASASAASADAAI/AVABAAAAAJk/5cg1hcjo_4s/photo.jpg?sz=50")
)
}
}
"return the social profile without an avatar url" in new WithApplication with Context {
val wsRequest = mock[MockWSRequest]
val wsResponse = mock[MockWSRequest#Response]
wsResponse.status returns 200
wsResponse.json returns Helper.loadJson("providers/oauth2/google.img.default.json")
wsRequest.get() returns Future.successful(wsResponse)
httpLayer.url(API.format("my.access.token")) returns wsRequest

profile(provider.retrieveProfile(oAuthInfo.as[OAuth2Info])) { p =>
p must be equalTo CommonSocialProfile(
loginInfo = LoginInfo(provider.id, "109476598527568979481"),
firstName = Some("Apollonia"),
lastName = Some("Vanova"),
fullName = Some("Apollonia Vanova"),
email = Some("apollonia.vanova@watchmen.com"),
avatarURL = None
)
}
}
}

/**
Expand Down
22 changes: 22 additions & 0 deletions silhouette/test/resources/providers/oauth2/google.img.default.json
@@ -0,0 +1,22 @@
{
"emails": [
{
"value": "home@watchmen.com",
"type": "home"
},
{
"value": "apollonia.vanova@watchmen.com",
"type": "account"
}
],
"id": "109476598527568979481",
"displayName": "Apollonia Vanova",
"name": {
"familyName": "Vanova",
"givenName": "Apollonia"
},
"image": {
"url": "https://lh6.googleusercontent.com/-m34A6I77dJU/ASASAASADAAI/AVABAAAAAJk/5cg1hcjo_4s/photo.jpg?sz=50",
"isDefault" : true
}
}
@@ -0,0 +1,22 @@
{
"emails": [
{
"value": "home@watchmen.com",
"type": "home"
},
{
"value": "apollonia.vanova@watchmen.com",
"type": "account"
}
],
"id": "109476598527568979481",
"displayName": "Apollonia Vanova",
"name": {
"familyName": "Vanova",
"givenName": "Apollonia"
},
"image": {
"url": "https://lh6.googleusercontent.com/-m34A6I77dJU/ASASAASADAAI/AVABAAAAAJk/5cg1hcjo_4s/photo.jpg?sz=50",
"isDefault" : false
}
}

0 comments on commit d0b3618

Please sign in to comment.