Replies: 1 comment 2 replies
-
Hi @brasta78 you are correct in that OAuth2 is not a core part of Unirest. One of the challenges is that there are browser/user parts of most flows that Unirest simply cannot do, and so require larger frameworks. What one would depend on your application framework. (Spring etc). However once you have an access token and a refresh token you could create a class that could deals with the expirations and refreshes to an extent. Keep in mind that a refresh token is basically a username/password, and so should be encrypted at rest and maybe not just hanging around in ram all the time even. In any case I would recommend your class keep track of the expiration itself and not wait for a 403 from the remote server. As far as Unirest is concerned this could be loaded as a lambda for the headers like this: Unirest.config().setDefaultHeader("Authorization", () -> myTokenManagingClass.getToken()) You could use Unirest itself to get the refreshed access token of course inside that same class. It would probably need a different configured instance to avoid a circular dependency with the outer ones default header (if you used that). There are a few supporting flows like this and client-credentials I've thought about adding to Unirest. I'll keep this issue open for those. |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm very happy using Unirest in my project, please point me to the right direction - my application has many Rest API clients which communicate with endpoint using OAuth2. I'm not sure how to deal with response error: "accesstoken expired" and how to use refreshtoken... It should be done using Interceptor or OAuth2 part is in general not Unirest side and I must use some OAuth library?
Thank You
Beta Was this translation helpful? Give feedback.
All reactions