Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Latest commit

 

History

History

AuthExamples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Mobile app showing the AeroGear Auth feature on Android

Author: Summers Pittman (secondsun)
Level: Beginner
Technologies: Java, Android
Summary: A basic example of HTTP Authentication
Source: https://github.com/aerogear/aerogear-android-cookbook/tree/master/AuthExamples

What is it?

Auth project demonstrates how to integrate HTTP Basic or HTTP Digest authentication into applications.

This simple project consists of a simple authenticated REST GET call.

This application is run on an Android device or emulator. It also requires the Authentication Server be running.

How do I run it?

System Requirements

Configure

Edit org.jboss.aerogear.android.cookbook.authexamples.Constants#URL_BASE to be the path of the application.

This application has an backend implementation in our Backend Cookbook and also an only version

In the case of a emulator and server are running on the same machine the URL will be http://10.0.2.2:8080/authentication/rest.

Build Application

$ cd /path/to/authExamples/
$ ./gradlew clean build

Running the app

To deploy, run and debug the application on an Android device attached to your system, on the command line enter the following:

$ cd /path/to/authExamples
$ ./gradlew installDebug

How does it work?

HowToUseHttpBasicAuthentication and HowToUseDigestAuthentication are two activities which create appropriate AuthenticationModules and associate them with Pipe objects. The UI provides buttons to log in, log out, and fetch data from the Authentication Server.

// Create a Authentication Module
HttpBasicAuthenticationConfiguration authenticationConfig = null;
try {
    authenticationConfig = AuthenticationManager
        .config("login", HttpBasicAuthenticationConfiguration.class)
        .baseURL(new URL(Constants.URL_BASE));
} catch (MalformedURLException e) {
    e.printStackTrace();
}

AuthenticationModule module = authenticationConfig.asModule();

// Create the pipe
RestfulPipeConfiguration pipeConfig = PipeManager
    .config("beer", RestfulPipeConfiguration.class)
    .module(authModule)
    .withUrl(new URL(Constants.URL_BASE + "/grocery/beers"));

Pipe<String> pipe = pipeConfig.forClass(String.class);

//use the pipe as normal
pipe.read(new YourCallback());

Notes

There are two regressions problems to be fixed:

  • AGDROID-349 - HttpDigest Module needs to be able to disable making a server call on logout
  • AGDROID-350 - HTTPBasic and HTTPDigest callbacks aren't triggered on the UI thread