protected class

ApplicationLinkRequestFactoryFactoryImpl.SalRequestFactoryAdapter

extends Object
implements ApplicationLinkRequestFactory
java.lang.Object
   ↳ com.atlassian.applinks.core.auth.ApplicationLinkRequestFactoryFactoryImpl.SalRequestFactoryAdapter

Summary

Public Constructors
ApplicationLinkRequestFactoryFactoryImpl.SalRequestFactoryAdapter(RequestFactory requestFactory)
Public Methods
ApplicationLinkRequest createRequest(Request.MethodType methodType, String url)
Creates a request of the given method type to the given url.
URI getAuthorisationURI(URI callback)

The URI that can be used to configure authentication for the requested resource.

URI getAuthorisationURI()
Provides a URI that can be used to configure authentication for the requested resource.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.atlassian.applinks.api.ApplicationLinkRequestFactory
From interface com.atlassian.applinks.api.AuthorisationURIGenerator

Public Constructors

public ApplicationLinkRequestFactoryFactoryImpl.SalRequestFactoryAdapter (RequestFactory requestFactory)

Public Methods

public ApplicationLinkRequest createRequest (Request.MethodType methodType, String url)

Creates a request of the given method type to the given url. ApplicationLinkRequestFactory implementations can be transparently authenticated by different AuthenticationProviders. See createAuthenticatedRequestFactory() for more details.

Example usage:

  ApplicationLinkRequestFactory requestFactory = createAuthenticatedRequestFactory();
  ApplicationLinkRequest request;

  try {
      request = requestFactory.createRequest(GET, "/rest/my-plugin/1.0/my-resource");
  } catch (CredentialsRequiredException e) {
      // we don't have credentials stored for the context user, so prompt user to authenticate
      // using the URI provided by getAuthorisationURI()
      // ...
  }

  try {
      boolean success = request.execute(new ApplicationLinkResponseHandler<Boolean>() {

          Boolean handle(Response response) throws ResponseException {
              return response.isSuccessful())
          }

          Boolean credentialsRequired(Response response) throws ResponseException {
              // the remote server rejected our credentials, so prompt the user to authenticate
              // using the URI provided by getAuthorisationURI()
              // ...
          }

      });

  } catch (ResponseException re) {
      // the request failed to complete normally
  }
 
Parameters
methodType The HTTP method type
url The target of the request. If you specify a URI that does not start with a protocol string (e.g. http: or https:) the target ApplicationLink's rpcUrl will be pre-pended to the request URI. Specified absolute URIs will be used as is.
Returns

public URI getAuthorisationURI (URI callback)

The URI that can be used to configure authentication for the requested resource.

The typical scenario is a call to an OAuth-protected remote resource for which the caller does not have an access token. If the caller has the ability to send a redirect (in case of a plugin servlet or webwork action), it would do so using this URL. This URL will take the user to a local endpoint that will perform the "OAuth dance":

  • request a Request Token from the remote OAuth provider
  • redirect the client to the provider's authorize URL, using itself for the callback
  • on successful approval by the user, swap the request token for an access token
  • redirect the user back to original resource (the plugin's servlet or action)
  • If the caller does not have the ability to perform an HTTP redirect to this URL (possibly because it's a Web Panel), it can display a link or button that will open the URL in a popup dialog with an iframe, allowing the user to perform the oauth dance at a later time.

    Parameters
    callback the URI to redirect to after authentication is complete
    Returns
    • the URL that can be used to provide authentication for the requested resource, or null if this request factory doesn't support authorisation via user intervention. Note, if this method returns a non-null value, getAuthorisationURI() MUST also return a non-null value.

    public URI getAuthorisationURI ()

    Provides a URI that can be used to configure authentication for the requested resource. This URI will not result in a callback. ApplicationLinkRequestFactory implementations that support authorisation URIs must return non-null values for this method at a minimum. Support for getAuthorisationURI(URI) is optional.

    Returns
    • the URL that can be used to configure authentication for the requested resource, or null if this request factory doesn't support authorisation via user intervention. If getAuthorisationURI(URI) returns a non-null value, this method MUST also return a non-null value.