Android OAuth2 Client

Android OAuth2 Client with embedded WebView for authorization url.

View the Project on GitHub gbazilio/oauth2client

Custom OAuth2 Android Client

The library was developed to fit specific needs of a client, which is to complete the OAuth Authorization Code Flow using Github as the OAuth2 Provider.

Using the library

Get an instance of a provider's client:

OAuth2Client oauthClient = OAuth2ClientFactory.newInstance(OAuth2ClientFactory.Provider.ENVATO);

Build the dialog fragment to show the login/authorization screen:

OAuth2LoginFragment oAuth2LoginFragment = OAuth2LoginFragment.newInstance(oauthClient);

Set a listener responsible for intercepting the access token when appropriate:

oAuth2LoginFragment.setOnAccessTokenRequestedListener(new AccessTokenRequested() {
    public void onAccessTokenRequested(Token token) {
        Log.v("Provider", token.getProvider());
        Log.v("AccessToken", token.getAccessToken());        

Be sure to make the fragment visible whenever you want (e.g. on clicking a button):

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.addToBackStack(null);, "oauth2_dialog");

OAuth2 Clients

Implement the base class com.gbazilio.oauth2client.oauth2.clients.interfaces.OAuth2Client if more clients are needed.