https://github.com/babbel/okhttp-aws-signer
AWS V4 signing algorithm for OkHttp requests
https://github.com/babbel/okhttp-aws-signer
Last synced: 11 months ago
JSON representation
AWS V4 signing algorithm for OkHttp requests
- Host: GitHub
- URL: https://github.com/babbel/okhttp-aws-signer
- Owner: babbel
- License: mit
- Created: 2018-10-02T09:06:07.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-07-14T13:34:15.000Z (almost 3 years ago)
- Last Synced: 2023-08-06T21:53:43.691Z (almost 3 years ago)
- Language: Kotlin
- Homepage:
- Size: 111 KB
- Stars: 30
- Watchers: 64
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# Okhttp AWS Signer
This is a kotlin library that implements the AWS V4 signing algorithm described [here](https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html) for the [OkHttp](https://square.github.io/okhttp/) requests. It has no dependency on the Amazon sdks.
## Getting the library
Currently the easiest way to get the library is by using [JitPack](https://jitpack.io/)
```groovy
dependencies {
implementation 'com.github.babbel:okhttp-aws-signer:'
}
```
You can also create a fat JAR by executing the gradle task `shadowJar`. This task comes from the [shadow](https://github.com/johnrengelman/shadow) plugin.
## Usage
You'll need to first setup the signer object:
```kotlin
val signer = OkHttpAwsV4Signer(region, serviceName)
```
`region` is the region you have your services running, i.e., `eu-west-1`.
`serviceName` should be the name of the service your calling, i.e., `execute-api`.
Once you have a request you can easily sign it with:
```kotlin
val newRequest = signer.sign(request, accessKeyId, accessKey)
```
The signing algorithm requires that the `host` and the `x-amz-date` headers be present in the request prior to signing. Please make sure to include them. The `x-amz-date` header must be formatted with the pattern `"yyyyMMdd'T'HHmmss'Z'"`.
## Developing
All changes are welcomed in the form of PRs. Please explain the change in the PR's description. We'll make our best to be swift in getting it through.
The gradle wrapper is not versioned under the repo, but can be easily downloaded by executing the task `wrapper` inside the file `wrapper.gradle`. A typical execution of this looks like:
```bash
gradle wrapper -b wrapper.gradle
```
To run the tests, please execute:
```bash
./gradlew clean test
```