1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
okhttp-signpost
========
A [Signpost][1] extension for signing [OkHttp][2] requests.
Download
=======
Gradle:
```gradle
compile 'se.akerfeldt:okhttp-signpost:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.0.0-RC1'
compile 'oauth.signpost:signpost-core:1.2.1.2'
```
Usage
=======
To use, simply create an instance of `OkHttpOAuthConsumer` passing in your consumer key/secret pair.
Set your token and token secret. Lastly, create a SigningInterceptor with your consumer and give it to your
`OkHttpClient.Builder`.
```java
OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
consumer.setTokenWithSecret(token, secret);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new SigningInterceptor(consumer))
.build();
```
The `SigningInterceptor` is a convenience for signing the request but is not mandatory. You could also sign your request
manually like so:
```java
OkHttpOAuthConsumer consumer = ...
Request request = new Request.Builder().build();
Request signedRequest = (Request) consumer.sign(request).unwrap();
Call call = okHttpClient.newCall(signedRequest);
```
Obviously, this fits very well with [Retrofit 2][3] as well. Just pass your OkHttpClient (containing the interceptor) to
Retrofit:
```java
OkHttpOAuthConsumer consumer = new OkHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
consumer.setTokenWithSecret(token, secret);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new SigningInterceptor(consumer))
.build();
return new Retrofit.Builder()
...
.client(okHttpClient)
.build();
```
License
=======
Copyright 2015 Patrik Ã…kerfeldt
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
[1]: https://github.com/mttkay/signpost
[2]: https://github.com/square/okhttp
[3]: https://github.com/square/retrofit
|