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

PasswordGrantProvider can not use #335

Closed
reoxu opened this issue Jan 9, 2023 · 8 comments
Closed

PasswordGrantProvider can not use #335

reoxu opened this issue Jan 9, 2023 · 8 comments

Comments

@reoxu
Copy link

reoxu commented Jan 9, 2023

we use

com.ocadotechnology
sttp-oauth2_2.12
0.15.2

got this err
image
How can we use PasswordGrantProvider in right way.

@jsienniak
Copy link
Collaborator

Hi @reoxu,

If you look at signature of PasswordGrantProvider:

def apply[F[_]: MonadThrow](
    tokenUrl: Uri,
    clientId: NonEmptyString,
    clientSecret: Secret[String]
  )(
    backend: SttpBackend[F, Any]
  ): PasswordGrantProvider[F]

You need to use an effect (F), for which you have and instance of both SttpBackend and MonadThrow, for example cats's IO. If you would share a type of your backend value I could help you more.

@bwiercinski
Copy link
Contributor

it have to be one of synchronous backend, as compiler is looking for cats.MonadThrow[Identity]. imo the library should input use sttp.model.MonadError not cats' MonadThrow. i've made similar migration in ac508e4 commit

@majk-p
Copy link
Member

majk-p commented Jan 9, 2023

Changes from @bwiercinski have been introduced in https://github.com/ocadotechnology/sttp-oauth2/releases/tag/v0.16.0

@reoxu please update the version, it should help with your issue

@reoxu
Copy link
Author

reoxu commented Jan 10, 2023

Changes from @bwiercinski have been introduced in https://github.com/ocadotechnology/sttp-oauth2/releases/tag/v0.16.0

@reoxu please update the version, it should help with your issue

Hi @majk-p, i download v0.16.0 source and try to build it, but failed.
image
I fix code
mdocVariables := Map(
"VERSION" -> "0.16.0"
// "VERSION" -> { if (isSnapshot.value) previousStableVersion.value.get else version.value } )
got jar file name like this sttp-oauth2_2.12-HEAD+20230110-1326.jar

@reoxu
Copy link
Author

reoxu commented Jan 10, 2023

I use sttp-oauth2_2.12-HEAD+20230110-1326.jar, got this err.
image
Maybe this pr need to test or i miss something
#336

@bwiercinski
Copy link
Contributor

@reoxu can you paste whole stacktrace?

@reoxu
Copy link
Author

reoxu commented Jan 10, 2023

@reoxu can you paste whole stacktrace?

Exception in thread "main" 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$5(PasswordGrantProvider.scala:30)
at cats.syntax.EitherOps$.leftMap$extension(either.scala:193)
at com.ocadotechnology.sttp.oauth2.PasswordGrantProvider$.$anonfun$apply$4(PasswordGrantProvider.scala:30)
at sttp.client3.monad.IdMonad$.map(IdMonad.scala:8)
at sttp.monad.syntax$MonadErrorOps.map(MonadError.scala:60)
at com.ocadotechnology.sttp.oauth2.PasswordGrantProvider$.$anonfun$apply$2(PasswordGrantProvider.scala:30)
at sttp.monad.syntax$MonadErrorOps.flatMap(MonadError.scala:61)
at com.ocadotechnology.sttp.oauth2.PasswordGrantProvider$.$anonfun$apply$1(PasswordGrantProvider.scala:31)
at OauthTest$.main(OauthTest.scala:18)
at OauthTest.main(OauthTest.scala)
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)
at sttp.client3.monad.IdMonad$.map(IdMonad.scala:8)
at sttp.monad.syntax$MonadErrorOps.map(MonadError.scala:60)
at sttp.client3.internal.BodyFromResponseAs.doApply(BodyFromResponseAs.scala:24)
at sttp.client3.internal.BodyFromResponseAs.$anonfun$apply$1(BodyFromResponseAs.scala:14)
at sttp.monad.syntax$MonadErrorOps.map(MonadError.scala:60)
at sttp.client3.internal.BodyFromResponseAs.apply(BodyFromResponseAs.scala:14)
at sttp.client3.HttpURLConnectionBackend.readResponse(HttpURLConnectionBackend.scala:245)
at sttp.client3.HttpURLConnectionBackend.$anonfun$send$1(HttpURLConnectionBackend.scala:56)
at scala.util.Try$.apply(Try.scala:209)
at sttp.monad.MonadError.handleError(MonadError.scala:24)
at sttp.monad.MonadError.handleError$(MonadError.scala:23)
at sttp.client3.monad.IdMonad$.handleError(IdMonad.scala:6)
at sttp.client3.SttpClientException$.adjustExceptions(SttpClientException.scala:58)
at sttp.client3.HttpURLConnectionBackend.adjustExceptions(HttpURLConnectionBackend.scala:295)
at sttp.client3.HttpURLConnectionBackend.send(HttpURLConnectionBackend.scala:30)
at sttp.client3.HttpURLConnectionBackend.send(HttpURLConnectionBackend.scala:22)
at sttp.client3.FollowRedirectsBackend.sendWithCounter(FollowRedirectsBackend.scala:29)
at sttp.client3.FollowRedirectsBackend.send(FollowRedirectsBackend.scala:24)
at com.ocadotechnology.sttp.oauth2.PasswordGrant$.$anonfun$requestToken$1(PasswordGrant.scala:40)
at sttp.monad.syntax$MonadErrorOps.map(MonadError.scala:60)
at com.ocadotechnology.sttp.oauth2.PasswordGrant$.requestToken(PasswordGrant.scala:42)
at com.ocadotechnology.sttp.oauth2.PasswordGrantProvider$.$anonfun$apply$3(PasswordGrantProvider.scala:29)
... 6 more
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)
... 30 more

Process finished with exit code 1

@bwiercinski
Copy link
Contributor

i've made an new issue since it is not related with this one. pls use #337. in my opinion this issue is solved and we are waiting with closing until the version is properly released.

@reoxu reoxu closed this as completed Jan 10, 2023
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

No branches or pull requests

4 participants