Skip to content

kuuuurt/ktor-client-oauth-feature

Repository files navigation

Ktor Client - OAuth Feature

A Kotlin Multiplatform library for automatically handling OAuth refreshes with Ktor

Usage

Just install the feature in your HttpClient and tell it how to:

  1. Get the access token
    • Get it from your cache or somewhere where you can update the token
  2. How to refresh the token
    • This function should get your new token then update the token which getToken is using
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.

Installation

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")

Maintainers

Contributing

Feel free to dive in! Open an issue or submit PRs.

License

Apache-2.0 © Kurt Renzo Acosta

About

Ktor Client Feature for handling OAuth token refreshes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages