GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - dpsm/android-auth: Android Authentication Library

BranchesTags
Open more actions menu

Latest commit

 

History

15 Commits
15 Commits

Folders and files

NameName
Last commit message
Last commit date
src
src
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
android-auth.iml
android-auth.iml
 
 
lint.xml
lint.xml
 
 
pom.xml
pom.xml
 
 
proguard-rules.pro
proguard-rules.pro
 
 

Repository files navigation

android-auth

An Android library to facilitate the selection of user accounts from the device and in obtaining Google OAuth tokens from the Google Play Services library.

Usage

The sections below illustrate how to use the library APIs in more detail.

AccountSelectionActivityHelper

This class is part of a family of helper classes that ease the integration with selecting a device account.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mAccountSelectionHelper = new AccountSelectionActivityHelper(this, REQUEST_CODE_BASE);
    ...
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (mAccountSelectionHelper.handleActivityResult(requestCode, resultCode, data)) {
        return; // Handled by helper...
    }
    ...
}

// The methods below to be implemented by the Activity/Fragment

@Override
public void onAccountSelected(final String accountName) {
    // An account has been selected. Do something with it :)
}

@Override
public void onAccountSelectionCanceled() {
    // User cancelled selection...
}

Tip: There are similar helper classes for the android.app.Fragment and android.support.v4.app.Fragment types.

GoogleOauthTokenObservable

This class facilitates obtaining Google OAuth tokens for a specified scope. The API is based on rxjava.

@Override
public void onAccountSelected(final String accountName) {
    GoogleOauthTokenObservable.create(this, accountName, GOOGLE_PRINT_SCOPE)
        .subscribeOn(Schedulers.io())
        .subscribe(new Action1<String>() {
            @Override
            public void call(final String token) {
                // Do something with the token!
            }
        });
    ...
}

Given that there might be a need for the user to authorize access to your application though a Google Play authorization screen, we provide an operator that hooks into a Fragment or Activity to ease the authorization flow.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mAuthenticationHelper = new OperatorGoogleAuthenticationActivityController(this, REQUEST_CODE_BASE + 100);
    ...
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (mAuthenticationHelper.handleActivityResult(requestCode, resultCode, data)) {
       return; // Handled by helper...
   }
   ...
}

@Override
public void onAccountSelected(final String accountName) {
    GoogleOauthTokenObservable.create(this, accountName, GOOGLE_PRINT_SCOPE)
        .authenticateUsing(this, REQUEST_CODE_BASE) // <= This registers the Fragment/Activity to the authorization flow!
        .subscribeOn(Schedulers.io())
        .subscribe(new Action1<String>() {
            @Override
            public void call(final String token) {
                // Do something with the token!
            }
        });
    ...
}

@Override
public void onAuthenticationError(final Throwable throwable) {
    Toast.makeText(this, "Unknown authentication error!", Toast.LENGTH_SHORT).show();
}

@Override
public void onAuthenticationSucceeded(final String token) {
    Toast.makeText(this, "Authenticated!", Toast.LENGTH_SHORT).show();
}

@Override
public void onRetryAuthentication() {
    Toast.makeText(this, "Retry Authentication!", Toast.LENGTH_SHORT).show();
}

About

Android Authentication Library

Resources

Readme
Apache-2.0 license
Activity

Stars

7 stars

Watchers

2 watching

Forks

4 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.