Class AuthorizationService
- java.lang.Object
-
- net.openid.appauth.AuthorizationService
-
public class AuthorizationService extends Object
Dispatches requests to an OAuth2 authorization service.Note that instances of this class must be manually disposed when no longer required, to avoid leaks (see
dispose()
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
AuthorizationService.RegistrationResponseCallback
Callback interface for token endpoint requests.static interface
AuthorizationService.TokenResponseCallback
Callback interface for token endpoint requests.
-
Constructor Summary
Constructors Constructor Description AuthorizationService(Context context)
Creates an AuthorizationService instance, using thedefault configuration
.AuthorizationService(Context context, AppAuthConfiguration clientConfiguration)
Creates an AuthorizationService instance, using the specified configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CustomTabsIntent.Builder
createCustomTabsIntentBuilder(Uri... possibleUris)
Creates a custom tab builder, that will use a tab session from an existing connection to a web browser, if available.void
dispose()
Disposes state that will not normally be handled by garbage collection.Intent
getAuthorizationRequestIntent(AuthorizationRequest request)
Constructs an intent that encapsulates the provided request and a default custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
When started, the intent launches anActivity
that sends an authorization request to the authorization service, using a custom tab.Intent
getAuthorizationRequestIntent(AuthorizationRequest request, CustomTabsIntent customTabsIntent)
Constructs an intent that encapsulates the provided request and custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
.BrowserDescriptor
getBrowserDescriptor()
Returns the BrowserDescriptor of the chosen browser.CustomTabManager
getCustomTabManager()
Intent
getEndSessionRequestIntent(EndSessionRequest request)
Constructs an intent that encapsulates the provided request and a default custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
When started, the intent launches anActivity
that sends an authorization request to the authorization service, using a custom tab.Intent
getEndSessionRequestIntent(EndSessionRequest request, CustomTabsIntent customTabsIntent)
Constructs an intent that encapsulates the provided request and custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
.void
performAuthorizationRequest(AuthorizationRequest request, PendingIntent completedIntent)
Sends an authorization request to the authorization service, using a custom tab if available, or a browser instance.void
performAuthorizationRequest(AuthorizationRequest request, PendingIntent completedIntent, PendingIntent canceledIntent)
Sends an authorization request to the authorization service, using a custom tab if available, or a browser instance.void
performAuthorizationRequest(AuthorizationRequest request, PendingIntent completedIntent, PendingIntent canceledIntent, CustomTabsIntent customTabsIntent)
Sends an authorization request to the authorization service, using a custom tab.void
performAuthorizationRequest(AuthorizationRequest request, PendingIntent completedIntent, CustomTabsIntent customTabsIntent)
Sends an authorization request to the authorization service, using a custom tab.void
performEndSessionRequest(EndSessionRequest request, PendingIntent completedIntent)
Sends an end session request to the authorization service, using a custom tab if available, or a browser instance.void
performEndSessionRequest(EndSessionRequest request, PendingIntent completedIntent, PendingIntent canceledIntent)
Sends an end session request to the authorization service, using a custom tab if available, or a browser instance.void
performEndSessionRequest(EndSessionRequest request, PendingIntent completedIntent, PendingIntent canceledIntent, CustomTabsIntent customTabsIntent)
Sends an end session request to the authorization service, using a custom tab.void
performEndSessionRequest(EndSessionRequest request, PendingIntent completedIntent, CustomTabsIntent customTabsIntent)
Sends an end session request to the authorization service, using a custom tab.void
performRegistrationRequest(RegistrationRequest request, AuthorizationService.RegistrationResponseCallback callback)
Sends a request to the authorization service to dynamically register a client.void
performTokenRequest(TokenRequest request, AuthorizationService.TokenResponseCallback callback)
Sends a request to the authorization service to exchange a code granted as part of an authorization request for a token.void
performTokenRequest(TokenRequest request, ClientAuthentication clientAuthentication, AuthorizationService.TokenResponseCallback callback)
Sends a request to the authorization service to exchange a code granted as part of an authorization request for a token.
-
-
-
Constructor Detail
-
AuthorizationService
public AuthorizationService(@NonNull Context context)
Creates an AuthorizationService instance, using thedefault configuration
.Note that instances of this class must be manually disposed when no longer required, to avoid leaks (see
dispose()
.
-
AuthorizationService
public AuthorizationService(@NonNull Context context, @NonNull AppAuthConfiguration clientConfiguration)
Creates an AuthorizationService instance, using the specified configuration.Note that instances of this class must be manually disposed when no longer required, to avoid leaks (see
dispose()
.
-
-
Method Detail
-
getCustomTabManager
public CustomTabManager getCustomTabManager()
-
getBrowserDescriptor
public BrowserDescriptor getBrowserDescriptor()
Returns the BrowserDescriptor of the chosen browser.Can for example be used to set the browsers package name to a CustomTabsIntent.
-
createCustomTabsIntentBuilder
public CustomTabsIntent.Builder createCustomTabsIntentBuilder(Uri... possibleUris)
Creates a custom tab builder, that will use a tab session from an existing connection to a web browser, if available.
-
performAuthorizationRequest
public void performAuthorizationRequest(@NonNull AuthorizationRequest request, @NonNull PendingIntent completedIntent)
Sends an authorization request to the authorization service, using a custom tab if available, or a browser instance.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the current activity will regain control.
-
performAuthorizationRequest
public void performAuthorizationRequest(@NonNull AuthorizationRequest request, @NonNull PendingIntent completedIntent, @NonNull PendingIntent canceledIntent)
Sends an authorization request to the authorization service, using a custom tab if available, or a browser instance.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the providedcancel PendingIntent
will be invoked.
-
performAuthorizationRequest
public void performAuthorizationRequest(@NonNull AuthorizationRequest request, @NonNull PendingIntent completedIntent, @NonNull CustomTabsIntent customTabsIntent)
Sends an authorization request to the authorization service, using a custom tab.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the current activity will regain control.- Parameters:
customTabsIntent
- The intent that will be used to start the custom tab. It is recommended that this intent be created with the help ofcreateCustomTabsIntentBuilder(Uri[])
, which will ensure that a warmed-up version of the browser will be used, minimizing latency.
-
performAuthorizationRequest
public void performAuthorizationRequest(@NonNull AuthorizationRequest request, @NonNull PendingIntent completedIntent, @Nullable PendingIntent canceledIntent, @NonNull CustomTabsIntent customTabsIntent)
Sends an authorization request to the authorization service, using a custom tab.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the providedcancel PendingIntent
will be invoked.- Parameters:
customTabsIntent
- The intent that will be used to start the custom tab. It is recommended that this intent be created with the help ofcreateCustomTabsIntentBuilder(Uri[])
, which will ensure that a warmed-up version of the browser will be used, minimizing latency.- Throws:
ActivityNotFoundException
- if no suitable browser is available to perform the authorization flow.
-
performEndSessionRequest
public void performEndSessionRequest(@NonNull EndSessionRequest request, @NonNull PendingIntent completedIntent)
Sends an end session request to the authorization service, using a custom tab if available, or a browser instance.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the current activity will regain control.
-
performEndSessionRequest
public void performEndSessionRequest(@NonNull EndSessionRequest request, @NonNull PendingIntent completedIntent, @NonNull PendingIntent canceledIntent)
Sends an end session request to the authorization service, using a custom tab if available, or a browser instance.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the providedcancel PendingIntent
will be invoked.
-
performEndSessionRequest
public void performEndSessionRequest(@NonNull EndSessionRequest request, @NonNull PendingIntent completedIntent, @NonNull CustomTabsIntent customTabsIntent)
Sends an end session request to the authorization service, using a custom tab.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the current activity will regain control.- Parameters:
customTabsIntent
- The intent that will be used to start the custom tab. It is recommended that this intent be created with the help ofcreateCustomTabsIntentBuilder(Uri[])
, which will ensure that a warmed-up version of the browser will be used, minimizing latency.
-
performEndSessionRequest
public void performEndSessionRequest(@NonNull EndSessionRequest request, @NonNull PendingIntent completedIntent, @Nullable PendingIntent canceledIntent, @NonNull CustomTabsIntent customTabsIntent)
Sends an end session request to the authorization service, using a custom tab.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the providedcompletion PendingIntent
will be invoked. If the user cancels the authorization request, the providedcancel PendingIntent
will be invoked.- Parameters:
customTabsIntent
- The intent that will be used to start the custom tab. It is recommended that this intent be created with the help ofcreateCustomTabsIntentBuilder(Uri[])
, which will ensure that a warmed-up version of the browser will be used, minimizing latency.- Throws:
ActivityNotFoundException
- if no suitable browser is available to perform the authorization flow.
-
getAuthorizationRequestIntent
public Intent getAuthorizationRequestIntent(@NonNull AuthorizationRequest request, @NonNull CustomTabsIntent customTabsIntent)
Constructs an intent that encapsulates the provided request and custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the activity that gets launched will callActivity.setResult(int)
withActivity.RESULT_OK
and anIntent
containing authorization completion information. If the user presses the back button or closes the browser tab, the launched activity will callActivity.setResult(int)
withActivity.RESULT_CANCELED
without a dataIntent
. Note thatActivity.RESULT_OK
indicates the authorization request completed, not necessarily that it was a successful authorization.- Parameters:
customTabsIntent
- The intent that will be used to start the custom tab. It is recommended that this intent be created with the help ofcreateCustomTabsIntentBuilder(Uri[])
, which will ensure that a warmed-up version of the browser will be used, minimizing latency.- Throws:
ActivityNotFoundException
- if no suitable browser is available to perform the authorization flow.
-
getAuthorizationRequestIntent
public Intent getAuthorizationRequestIntent(@NonNull AuthorizationRequest request)
Constructs an intent that encapsulates the provided request and a default custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
When started, the intent launches anActivity
that sends an authorization request to the authorization service, using a custom tab.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the activity that gets launched will callActivity.setResult(int)
withActivity.RESULT_OK
and anIntent
containing authorization completion information. If the user presses the back button or closes the browser tab, the launched activity will callActivity.setResult(int)
withActivity.RESULT_CANCELED
without a dataIntent
. Note thatActivity.RESULT_OK
indicates the authorization request completed, not necessarily that it was a successful authorization.- Throws:
ActivityNotFoundException
- if no suitable browser is available to perform the authorization flow.
-
getEndSessionRequestIntent
public Intent getEndSessionRequestIntent(@NonNull EndSessionRequest request, @NonNull CustomTabsIntent customTabsIntent)
Constructs an intent that encapsulates the provided request and custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the activity that gets launched will callActivity.setResult(int)
withActivity.RESULT_OK
and anIntent
containing authorization completion information. If the user presses the back button or closes the browser tab, the launched activity will callActivity.setResult(int)
withActivity.RESULT_CANCELED
without a dataIntent
. Note thatActivity.RESULT_OK
indicates the authorization request completed, not necessarily that it was a successful authorization.- Parameters:
customTabsIntent
- The intent that will be used to start the custom tab. It is recommended that this intent be created with the help ofcreateCustomTabsIntentBuilder(Uri[])
, which will ensure that a warmed-up version of the browser will be used, minimizing latency.- Throws:
ActivityNotFoundException
- if no suitable browser is available to perform the authorization flow.
-
getEndSessionRequestIntent
public Intent getEndSessionRequestIntent(@NonNull EndSessionRequest request)
Constructs an intent that encapsulates the provided request and a default custom tabs intent, and is intended to be launched viaActivity.startActivityForResult(android.content.Intent, int)
When started, the intent launches anActivity
that sends an authorization request to the authorization service, using a custom tab.The parameters of this request are determined by both the authorization service configuration and the provided
request object
. Upon completion of this request, the activity that gets launched will callActivity.setResult(int)
withActivity.RESULT_OK
and anIntent
containing authorization completion information. If the user presses the back button or closes the browser tab, the launched activity will callActivity.setResult(int)
withActivity.RESULT_CANCELED
without a dataIntent
. Note thatActivity.RESULT_OK
indicates the authorization request completed, not necessarily that it was a successful authorization.- Throws:
ActivityNotFoundException
- if no suitable browser is available to perform the authorization flow.
-
performTokenRequest
public void performTokenRequest(@NonNull TokenRequest request, @NonNull AuthorizationService.TokenResponseCallback callback)
Sends a request to the authorization service to exchange a code granted as part of an authorization request for a token.The result of this request will be sent to the provided callback handler.
-
performTokenRequest
public void performTokenRequest(@NonNull TokenRequest request, @NonNull ClientAuthentication clientAuthentication, @NonNull AuthorizationService.TokenResponseCallback callback)
Sends a request to the authorization service to exchange a code granted as part of an authorization request for a token.The result of this request will be sent to the provided callback handler.
-
performRegistrationRequest
public void performRegistrationRequest(@NonNull RegistrationRequest request, @NonNull AuthorizationService.RegistrationResponseCallback callback)
Sends a request to the authorization service to dynamically register a client.The result of this request will be sent to the provided callback handler.
-
dispose
public void dispose()
Disposes state that will not normally be handled by garbage collection.This should be called when the authorization service is no longer required, including when any owning activity is paused or destroyed (i.e. in
Activity.onStop()
).
-
-