Client credentials grant
ClientCredentials and traits AccessTokenProvider and TokenIntrospection expose methods that:
- Obtain token via
requestToken introspectthe token for its details likeUserInfo
Caching#
Caching modules provide cached AccessTokenProvider, which can:
- reuse the token multiple times using a cache (default cache implementation may be overridden using appropriate constructor functions)
- fetch a new token if the previous one expires
| module name | class name | provided cache implementation | semaphore | notes |
|---|---|---|---|---|
sttp-oauth2-cache-cats | CachingAccessTokenProvider | cats-effect3's Ref | cats-effect2's Semaphore | |
sttp-oauth2-cache-zio | CachingAccessTokenProvider | zio's Ref | zio's Semaphore | |
sttp-oauth2-cache-future | FutureCachingAccessTokenProvider | monix-execution's AtomicAny | monix-execution's AsyncSemaphore | It only uses submodule of whole monix project |
Cats example#
sttp-oauth2 backends#
SttpOauth2ClientCredentialsBackend is a GenericBackend which sends auth bearer headers for every http call performed with it using provided AccessTokenProvider.
In order to cache tokens, use one of the AccessTokenProviders described in Caching section.