| Interface | Description |
|---|---|
| Authenticator |
Interface that defines the functionality of an Authenticator.
|
| AuthenticatorBuilder |
A builder interface that enables construction of
Authenticator instances. |
| AuthenticatorClientCallback |
Defines the client implemented callback that is called
when an
Authenticator completes authentication. |
| AuthenticatorReport |
Interface that defines the functionality of a Authentication Report object.
|
| IdentityProvider |
Defines an OAuth2 Identity Provider with all of its associated
identifiers and end points.
|
| IdentityProviderBuilder |
A builder that enables construction of
IdentityProvider instances. |
| InvokeClientCallback |
Defines the client implemented callback that is called
when a call to
ServiceContext#invoke(Context, InvokeTask, long)
completes. |
| Report |
Defines the base report interface.
|
| ServiceContext |
The principal SDK service context interface containing methods for:
SDK cached content life cycle
Symmetric Key Management
Symmetric Key Management
Identity Provider Persistence
Authentication Persistence
SDK Settings
|
| ServiceContext.RollKeyCallback |
Defines the interface that must be implemented by the callback object
passed to the
rollKey(Context, ServiceContext.RollKeyCallback) method. |
| UnAuthenticator |
Interface that defines the functionality of an UnAuthenticator.
|
| UnAuthenticatorBuilder |
A builder interface that enables construction of
UnAuthenticator instances. |
| UnAuthenticatorClientCallback |
Defines the client implemented callback that is called
when an
UnAuthenticator completes un-authentication. |
| UnAuthenticatorReport |
Interface that defines the functionality of a Un-Authentication Report object.
|
| Class | Description |
|---|---|
| AuthCodeCanceledActivity |
Defines a callback invoked by the AppAuth SDK when the end user
cancels the authentication process.
|
| AuthCodeResolutionActivity |
Defines a callback invoked by the AppAuth SDK when the end user
completes the authentication process and the authorization code
then needs to be resolved.
|
| IdentityProviderUtil |
A helper class that defines convience methods for working with
IdentityProvider instances. |
| InvokeTask |
The base asyc task class that allows calls to
ServiceContext#invokeWithFreshToken(Context, InvokeTask, long)
to be executed asynchronously and customized to perform client operations. |
| InvokeTaskHttpGet |
Convenience implementation of a
InvokeTask that performs a simple HTTP GET
to a destinationUrl and provides components of the response to the client
process. |
| ServiceContextFactory |
A factory that produces instances of
ServiceContext |
| UnAuthenticateCompleteCallback |
Created by SJensen on 4/13/2017.
|
| Exception | Description |
|---|---|
| AuthenticatorException |
Specific exceptions associated with the authentication process.
|
Microfocus Android Mobile SDK
ServiceContextFactorygetInstance() to obtain an ServiceContext.ServiceContextIdentityProviderIdentityProviderBuilderIdentityProvider instances. Obtained from the
ServiceContextFactory interface.AuthenticatorAuthenticatorReport back to the
client application that details the authentication status, and tokens.AuthenticatorBuilderAuthenticator instances. Obtained from the
ServiceContext interface.AuthenticatorClientCallbackAuthenticatorReportAuthenticatorClientCallback callback mechanism.UnAuthenticatorUnAuthenticatorReport
back to the client application that details the un-authentication status.UnAuthenticatorBuilderUnAuthenticator instances. Obtained from the
ServiceContext interface.UnAuthenticatorClientCallbackUnAuthenticatorReportUnAuthenticatorClientCallback callback mechanism.ServiceContext interfaceServiceContext object. This object will
be used to get builders, persist objects, access settings, and perform actions. For most SDK
functionality, this is the class that will provide the starting point.
An instance of a ServiceContext may be obtained by calling the
ServiceContextFactory.getInstance()
static method. After the first time it is called, there is little overhead in repeatedly calling
the getInstance() method, so caching the returned reference is not required. It is
expected that client application code will have many calls to getInstance().
ServiceContext svcContext = ServiceContextFactory.getInstance();
... Make calls using the context
The first implementation item that must be done in client application code is to initialize
the ServiceContext instance. This object must follow the lifecycle of the
client application's main Android activity. To accomplish this, add calls into the
ServiceContext object from the client Android application's main activity
lifecycle methods onStart(), onPause(), onResume() and onStop().
protected void onStart() {
super.onStart();
ServiceContextFactory.getInstance().onStart(this);
..... Additional handling
}
protected void onResume() {
super.onResume();
ServiceContextFactory.getInstance().onResume();
..... Additional handling
}
protected void onPause() {
super.onPause();
ServiceContextFactory.getInstance().onPause();
..... Additional handling
}
protected void onStop() {
super.onStop();
ServiceContextFactory.getInstance().onStop();
..... Additional handling
}
IdentityProvider object.
Once the Identity Provider data has been gathered, obtain an
IdentityProviderBuilder and
instantiate an IdentityProvider instance as follows:
IdentityProviderBuilder builder =
ServiceContextFactory.getInstance().getIdentityProviderBuilder(...);
... call additional builder setters if necessary
IdentityProvider identityProvider = builder.build();
The ServiceContextFactory provides multiple versions of the
getIdentityProviderBuilder method. Please see the JavaDoc describing each of the
methods to decide which signature is appropriate.
ServiceContext.getIdentityProviderBuilder(String providerUrl, String clientId, String clientSecret, String redirectURI)
ServiceContext.getIdentityProviderBuilder(String json)
ServiceContext.getIdentityProviderBuilder(IdentityProvider source)
Once an IdentityProvider instance is obtained, it may be persisted to the application
storage as follows:
ServiceContextFactory.getInstance().putIdentityProvider(
Context context,
IdentityProvider identityProvider);
Only one IdentityProvider instance may be persisted at a time. All authentication and
un-authentication operations use the currently persisted IdentityProvider. Attempting
to authenticate or un-authenticate without having a persisted IdentityProvider will result
in an exception.
Authenticator to authenticate an end userIdentityProvider instance is persisted, then the client application can
authenticate the end user using the described IdentityProvider. A typical client side
authentication implementation looks like this:
private class ClientAuthenticatorCallbackImpl
implements AuthenticatorCallback
{
public void onAuthenticationComplete (AuthenticatorReport report)
{
if (report.isAuthenticated())
{
String accessToken = report.getAccessToken();
... Do something with the access token
// Note that in this case there still may exist an exception if the refresh token
// was expired. If an access token refresh was attempted and failed because the
// refresh token was expired then an exception will be logged under the access token
// refresh category. However, the authentication could still be successful because
// an automatic complete re-authentication would be initiated, and may be
// successful.
}
else if (report.existsAnyExceptions())
{
... Get the exception and display an end user message
}
// Check to see if the Identity Provider was updated
if ((report.identityProviderConfigurationRefreshInitiated()) &&
(null == report.getIdentityProviderConfigurationRefreshExceptions()))
{ // The identity provider changed due to a successful discovery,
// update the client's cached copy of the Identity Provider to match the new
// persisted Identity Provider.
myClientIdentityProvider = report.getIdentityProvider()
}
}
}
Authenticator authenticator =
ServiceContextFactory.getInstance().getAuthenticatorBuilder(context,
identityProvider.getHost(),
identityProvider.getClientId(),
new ClientAuthenticatorCallbackImpl())
.build();
ServiceContextFactory.getInstance().authenticate(authenticator);
The ServiceContextFactory.getInstance().authenticate(authenticator) call may return
immediately with an exception. Generally, if this method throws an exception, then the
AuthenticatorClientCallback will not be called
and the client code must clean up after the failed authentication.
If ServiceContextFactory.getInstance().authenticate(authenticator) does not throw
an exception, then it can be assumed that the
AuthenticatorClientCallback
will be called and client code must react to the end of the authentication in that callback.
If an IdentityProvider has not been persisted, then the
ClientAuthenticatorCallbackImpl will be called with a
AuthenticatorException.IDENTITY_PROVIDER_NOT_RESOLVABLE
exception.
Generally, once the client application code calls the SDK to persist an IdentityProvider
instance, the SDK will not alter the IdentityProvider content. However, there is one case
where the SDK may alter the IdentityProvider content. If the SDK performs an OAuth2 Identity
Provider Discovery request and receives metadata describing the IdentityProvider, then the
SDK will automatically persist (update) the currently persisted IdentityProvider with the metadata information.
In this scenario, the client code may want to update their copy of the IdentityProvider
with the newly discovered data. To do this, the client code would place code inside the
AuthenticatorClientCallback.onAuthenticationComplete(com.microfocus.android.mobile.sdk.library.AuthenticatorReport)
method that checks
AuthenticatorReport.identityProviderConfigurationRefreshInitiated()
for a true return. In this case, the IdentityProvider supplied by the AuthenticatorReport
contains the updated data and is provided so that clients may use that instance as their new "cached"
copy of the IdentityProvider.
Please see the above code fragment for an example of how to determine if the IdentityProvider
was updated and how to get the new instance.
Authentication may be a very heavy weight process if no OAuth2 refresh token exists. In this case,
the user may be required to enter credentials at the Identity Provider as part of a full
authentication. A middle ground exists where the OAuth2 access token is expired and must be refreshed.
On the other extreme, authentication may be a very light weight operation if
a valid OAuth2 access token already exists. In this case, the authentication process simply
determines that the access token is still valid and provides it back to the client inside of the
AuthenticatorReport object.
ServiceContext.authenticate(Authenticator)
method to obtain tokens because it automatically ensures the tokens are fresh and provides
all user interaction if tokens need to be updated. There is, however, another, more direct,
way to get an access token.
long somePreDeterminedTime = (20 * DateTimeUtil.SECOND_IN_MILLIS);
long millisecondsToExpiration = ServiceContextFactory.getInstance().getTimeToAccessTokenExpiration(AuthenticateActivity.this, identityProvider);
if (somePreDeterminedTime < millisecondsToExpiration)
{
String accessToken = ServiceContextFactory.getInstance().getAccessToken(context, identityProvider);
... Do something with the access token that is sure to take less than somePreDeterminedTime
}
<activity android:name="net.openid.appauth.RedirectUriReceiverActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="someclientscheme"
android:host="someclienthost"
android:path="someclientpath"/>
</intent-filter>
</activity>
ServiceContext.invokeWithFreshToken() method provides asynchronous execution of
a client implemented task. Generally, it is expected that client HTTP requests will be made using
this mechanism.
To use this method:
1) Create a sub-class of InvokeTask that performs the desired operation. The sub-class
may use the optional InvokeClientCallback mechanism to be notified of the task completion
or it may forgoe the callback if all "completion" code may be implemented in the task's
onPostExecute() method.
2) Invoke the method with a new instance of the InvokeTask.
This method will check the expiration time of any existing access token and may contact the
OAuth2 server to obtain a newly minted token. It will then set the access token into the
InvokeTask instance and then call its execute() method.
For complete details please refer to the JavaDoc headers for the following:
com.microfocus.android.mobile.sdk.library.ServiceContext.invokeWithFreshToken(android.content.Context, com.microfocus.android.mobile.sdk.library.InvokeTask, long)
InvokeTask
InvokeClientCallback