A Kotlin Multiplatform library for automatically handling OAuth refreshes with Ktor
Just install the feature in your HttpClient and tell it how to:
- Get the access token
- Get it from your cache or somewhere where you can update the token
- How to refresh the token
- This function should get your new token then update the token which
getTokenis using
- This function should get your new token then update the token which
HttpClient(yourEngine) { ... install(OAuthFeature) { getToken = { ... } refreshToken = { ... } } }This would add an Authorization: Bearer ${getToken()} header to your requests and would call refreshToken() when the request receives a 401 Unauthorized.
Check the table below for the compatibilty across Kotlin versions
| Library | Kotlin |
|---|---|
| 0.1.+ | 1.3.70 |
Add the repository on your Project-level gradle
allprojects { repositories { ... maven(url = "https://dl.bintray.com/kuuuurt/libraries") } }On the module-level, add the library as a dependency
kotlin { ... sourceSets["commonMain"].dependencies { implementation("com.kuuuurt:ktor-client-oauth-feature:0.1.1") } }This uses Gradle Module Metadata so enable it in your settings.gradle file
enableFeaturePreview("GRADLE_METADATA")- Kurt Renzo Acosta - kurt.r.acosta@gmail.com
Feel free to dive in! Open an issue or submit PRs.
Apache-2.0 © Kurt Renzo Acosta