Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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