Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kuuuurt/ktor-client-oauth-feature
Ktor Client Feature for handling OAuth token refreshes
https://github.com/kuuuurt/ktor-client-oauth-feature
Last synced: 6 days ago
JSON representation
Ktor Client Feature for handling OAuth token refreshes
- Host: GitHub
- URL: https://github.com/kuuuurt/ktor-client-oauth-feature
- Owner: kuuuurt
- License: apache-2.0
- Created: 2020-04-08T06:39:23.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-21T05:57:29.000Z (over 4 years ago)
- Last Synced: 2024-08-02T09:26:20.722Z (3 months ago)
- Language: Kotlin
- Homepage:
- Size: 754 KB
- Stars: 30
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin-multiplatform - ktor-client-oauth-feature - Ktor Client Feature for handling OAuth token refreshes (Libraries / Network)
README
# 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```kotlin
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
```kotlin
allprojects {
repositories {
...
maven(url = "https://dl.bintray.com/kuuuurt/libraries")
}
}
```On the module-level, add the library as a dependency
```kotlin
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
```kotlin
enableFeaturePreview("GRADLE_METADATA")
```## Maintainers
- Kurt Renzo Acosta - [[email protected]](mailto:[email protected])
## Contributing
Feel free to dive in! [Open an issue](https://github.com/kuuuurt/ktor-client-oauth-feature/issues) or submit PRs.
## License
[Apache-2.0](LICENSE) © Kurt Renzo Acosta