All Projects → mimicmobile → Okhttp Oauth2 Client

mimicmobile / Okhttp Oauth2 Client

Licence: apache-2.0
Android OAuth2 client using OkHttp

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Okhttp Oauth2 Client

Newspaper
An aggregated newspaper app containing news from 10+ local news publishers in Hong Kong. Made with ❤
Stars: ✭ 82 (-57.51%)
Mutual labels:  rxjava, okhttp3
Novate
A safety client by Https for android, (Android网络框架,基于Retrofit和RxJava打造的链式网络库, 支持okhttp的调用风格,又兼容Retrofit API,并支持rxJava链式操作)
Stars: ✭ 1,442 (+647.15%)
Mutual labels:  rxjava, okhttp3
Capacitor Oauth2
Capacitor OAuth 2 client plugin with support for the Web, iOS and Android! Show your appreciation with a Github ★
Stars: ✭ 84 (-56.48%)
Mutual labels:  oauth2, oauth2-client
Oauth2
OAuth2 framework for macOS and iOS, written in Swift.
Stars: ✭ 983 (+409.33%)
Mutual labels:  oauth2, oauth2-client
Oidc.example
OIDC (OpenID Connect) Example for http://openid.net/connect/
Stars: ✭ 190 (-1.55%)
Mutual labels:  oauth2, oauth2-client
Psraw
PowerShell Reddit API Wrapper
Stars: ✭ 42 (-78.24%)
Mutual labels:  oauth2, oauth2-client
Flask Oauthlib
YOU SHOULD USE https://github.com/lepture/authlib
Stars: ✭ 1,429 (+640.41%)
Mutual labels:  oauth2, oauth2-client
Retroauth
A library build on top of retrofit, for simple handling of authenticated requests
Stars: ✭ 405 (+109.84%)
Mutual labels:  oauth2, oauth2-client
Androidstarter
A sample Android app using the MVP architecture.
Stars: ✭ 140 (-27.46%)
Mutual labels:  rxjava, okhttp3
Auth
Authenticator via oauth2
Stars: ✭ 118 (-38.86%)
Mutual labels:  oauth2, oauth2-client
Fcfrtmvp
🔥FcfrtMvp+RxHttp+RxJava(Kotlin和JAVA共用完美支持)支持一键创建MVP项目,框架简约风格及详细注释,欢迎 star or fork!
Stars: ✭ 23 (-88.08%)
Mutual labels:  rxjava, okhttp3
Loginpass
Login with Google, GitHub, Twitter, Facebook and many other networks.
Stars: ✭ 177 (-8.29%)
Mutual labels:  oauth2, oauth2-client
Oauth2
OAuth2 client in Go
Stars: ✭ 20 (-89.64%)
Mutual labels:  oauth2, oauth2-client
Psmsgraph
A PowerShell module for the Microsoft Graph API
Stars: ✭ 71 (-63.21%)
Mutual labels:  oauth2, oauth2-client
Bilibili Android Client
An unofficial bilibili client for android http://www.jianshu.com/p/f69a55b94c05 -- 该项目已停止维护!
Stars: ✭ 4,430 (+2195.34%)
Mutual labels:  rxjava, okhttp3
Linkedin Api Php Client
LinkedIn API PHP SDK with OAuth 2 support. Can be used for social sign in or sharing on LinkedIn. Has a good usage examples
Stars: ✭ 88 (-54.4%)
Mutual labels:  oauth2, oauth2-client
Androidproject
Android 技术中台,但愿人长久,搬砖不再有
Stars: ✭ 4,398 (+2178.76%)
Mutual labels:  rxjava, okhttp3
Oauth2
Go OAuth2
Stars: ✭ 3,941 (+1941.97%)
Mutual labels:  oauth2, oauth2-client
Hoauth2
haskell oauth2 binding
Stars: ✭ 111 (-42.49%)
Mutual labels:  oauth2, oauth2-client
Beaver
Android MVVM + Dagger 2 (Hilt) + JetPack project template
Stars: ✭ 144 (-25.39%)
Mutual labels:  rxjava, oauth2

OkHttp OAuth2 client

A modern Android oAuth2 library using OkHttp with resource owner password grant types and easy token refreshing. This library aims to provide a solution for the less commonly used resource owner password grant type as well as providing dynamic parameter support that can be used with frameworks that allow for more flexible and dynamic oAuth2 parameters (such as the Django REST framework social oAuth2 library)

License Release Download

Gradle

The Gradle dependency is available via jCenter. jCenter is the default Maven repository used by Android Studio.

dependencies {
    // ... other dependencies here
    compile 'ca.mimic:oauth2library:2.4.2'
}

Usage

OAuth2Client client = new OAuth2Client.Builder("username", "password", "client-id", "client-secret", "site").build();
OAuthResponse response = client.requestAccessToken();

if (response.isSuccessful()) {
    String accessToken = response.getAccessToken();
    String refreshToken = response.getRefreshToken();
} else {
    OAuthError error = response.getOAuthError();
    String errorMsg = error.getError();
}

response.getCode();   // HTTP Status code

To refresh a token (defaults to "refresh_token" grant type)

OAuth2Client client = new OAuth2Client.Builder("client-id", "client-secret", "site").build();
OAuthResponse response = client.refreshAccessToken("refresh-token");
String accessToken = response.getAccessToken();

Callbacks

client.requestAccessToken(new OAuthResponseCallback() {
    @Override
    public void onResponse(OAuthResponse response) {
        if (response.isSuccessful()) {
            // response.getAccessToken();
        } else {
            // response.getOAuthError();
        }
    }
});

Builder options and parameters

Parameters for the builder

OAuth2Client.Builder builder = new OAuth2Client.Builder("client-id", "client-secret", "site")
        .grantType("grant-type")
        .scope("scope")
        .username("username")
        .password("password");

Provide your own OkHttpClient to the builder

OkHttpClient client = new OkHttpClient();

OAuth2Client.Builder builder = new OAuth2Client.Builder("client-id", "client-secret", "site")
        .okHttpClient(client);

Provide additional name / value string parameters

Map<String, String> map = new HashMap<>();
map.put("backend", "example-backend");

OAuth2Client.Builder builder = new OAuth2Client.Builder("client-id", "client-secret", "site")
        .parameters(map)

Wrap with RxJava!

OAuth2Client.Builder builder = new OAuth2Client.Builder("client-id", "client-secret", "http://localhost:8000/auth/token");
final OAuth2Client client = builder.build();

Observable<OAuthResponse> observable = Observable.fromCallable(new Callable<OAuthResponse>() {
    @Override
    public OAuthResponse call() throws Exception {
        return client.refreshAccessToken("refresh-token");
    }
});

observable.subscribe(new Action1<OAuthResponse>() {
    @Override
    public void call(OAuthResponse oAuthResponse) {
        oAuthResponse.getAccessToken();
    }
});

Extra response data

OAuthResponse contains other potentially helpful data

OAuthResponse response = client.requestAccessToken();
response.getHttpResponse();   // OkHttp response
response.getBody();           // Response body string
response.isJsonResponse();    // Was JSON parsed?

Acknowledgments

This library was inspired by the android-oauth2-client library by Daniel Szmulewicz

License

Copyright 2018 Mimic Mobile

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].