sttp-oauth2 icon indicating copy to clipboard operation
sttp-oauth2 copied to clipboard

Support partial Oauth2TokenResponse

Open kubukoz opened this issue 4 years ago • 2 comments

The Spotify API only returns:

  • access_token
  • token_type
  • expires_in
  • refresh_token
  • scope

kubukoz avatar Dec 22 '20 17:12 kubukoz

I guess this also relates to other types, like UserInfo - sometimes we'll need to support custom codecs.

kubukoz avatar Dec 22 '20 17:12 kubukoz

I'm trying to use PasswordGrant against a Keycloak instance, which causes a deserialization error:

com.ocadotechnology.sttp.oauth2.common$OAuth2Exception: Client call resulted in error (200): Missing required field: DownField(user_name)
        at com.ocadotechnology.sttp.oauth2.PasswordGrantProvider$.$anonfun$apply$3(PasswordGrantProvider.scala:26)
        at cats.syntax.EitherOps$.leftMap$extension(either.scala:172)
        at com.ocadotechnology.sttp.oauth2.PasswordGrantProvider$.$anonfun$apply$2(PasswordGrantProvider.scala:26)
        ...
Caused by: com.ocadotechnology.sttp.oauth2.common$Error$HttpClientError: Client call resulted in error (200): Missing required field: DownField(user_name)
        at com.ocadotechnology.sttp.oauth2.common$.$anonfun$responseWithCommonError$1(common.scala:103)
        at sttp.client3.MappedResponseAs.$anonfun$mapWithMetadata$1(ResponseAs.scala:91)
        at sttp.client3.internal.BodyFromResponseAs.$anonfun$doApply$2(BodyFromResponseAs.scala:24)
        ...
Caused by: sttp.client3.DeserializationException: Missing required field: DownField(user_name)
        at sttp.client3.ResponseAs$.$anonfun$deserializeWithError$1(ResponseAs.scala:201)
        at sttp.client3.ResponseAs$.$anonfun$deserializeRightWithError$1(ResponseAs.scala:180)
        at sttp.client3.MappedResponseAs.$anonfun$mapWithMetadata$1(ResponseAs.scala:91)

The token endpoint essentially returns the fields in OAuth2TokenResponse (plus a few others), but not the extra ones from ExtendedOAuth2TokenResponse, so I guess that's the issue here because PasswordGrant still expects an ExtendedOAuth2TokenResponse.

I'm not too familiar with the codebase yet. Would it be possible to parameterize PasswordGrant to expect a custom token response like it's already done for AuthorizationCodeGrant in #104?

sbrunk avatar Jul 11 '22 12:07 sbrunk