Giter Site home page Giter Site logo

okhttp-signpost's Introduction

okhttp-signpost

A Signpost extension for signing OkHttp requests.

Download

Gradle:

    compile 'se.akerfeldt:okhttp-signpost:1.1.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.

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:

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 as well. Just pass your OkHttpClient (containing the interceptor) to Retrofit:

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.

okhttp-signpost's People

Contributors

bacza avatar blad avatar javiergamarra avatar johnjohndoe avatar justasm avatar pakerfeldt avatar shiki avatar swankjesse avatar yankeppey avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

okhttp-signpost's Issues

POST header goes empty

Thanks for the wrapper, first of all.
I am trying to use it for accessing a Magento web service.
But my retrofit request shows an empty POST header on which, the server returns a 500.

Any idea why that would happen?
Is there a way to use it?
I am using it the same way you've demonstrated on the product page.
Please advise

Add support for authorization flow

This wrapper fulfills the first purpose of Signpost -- signing HTTP messages -- but not the second -- requesting tokens from the OAuth service provider.

Would it be appropriate to add support for the authorization flow (i.e. via an OkHttpOAuthProvider and OkHttpResponseAdapter), or is this outside the scope of this extension?

Deploy to maven central

Would you like to deploy this to maven central?
I'm using your lib as a dependency and if I want to publish my plugin to maven central I need your lib to be there too.

Either you upload it to maven central or I have to fork it and do it on my group id.

Thanks for this lib ;)

Gives Me 401 Error

Im using okhttp-signpost with Retrofit.

Before i was using signspot for it but unfortunately now it gives me 401 error. and my current code is look like below

    val consumerKey = "Key"
    val consumerSecret = "Secret Key"
    val accessToken = "AccessToke"
    val tokenSecret = "TokenSecret"

    val consumer = OkHttpOAuthConsumer(consumerKey, consumerSecret)
    consumer.setTokenWithSecret(accessToken, tokenSecret)

    val interceptor = HttpLoggingInterceptor()
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
    val client: OkHttpClient = OkHttpClient.Builder().connectTimeout(20, TimeUnit.SECONDS)
        .writeTimeout(20, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS)
        .addInterceptor(SigningInterceptor(consumer))
        .addInterceptor(interceptor).build()

    Retrofit.Builder().baseUrl(baseUrl).client(client).addConverterFactory(GsonConverterFactory.create()).build()

But in PostMan Api Callled Successfully When i applied different approch then i found if I add authorization data to Request Body then it call successfully and when i add authorization data to header then gives me same error.

Thats how we need to add keys as body,url.

How to update HMAC-SHA1 to HMAC-SHA256 in android lib

HMAC-SHA1 will no longer be accepted as a signature method for TBA integrations. Before your account is upgraded to 2023.1, you must update your TBA integrations to use the HMAC-SHA256 signature method. Please solve the issue

There is a problem with Android 5.1

java.lang.NoClassDefFoundError: Failed resolution of: Lse/akerfeldt/okhttp/signpost/OkHttpOAuthConsumer;

compile files('libs/okhttp-signpost-1.1.0.jar')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.