public interface AtlassianHostRestClients
RestTemplates to make authenticated requests to Atlassian hosts.
To make requests using JWT, the add-on must specify the authentication type jwt in its add-on descriptor.
To obtain a RestTemplate using JWT authentication, use authenticatedAsAddon():
@Autowired private AtlassianHostRestClients restClients; public void makeRequest() { restClients.authenticatedAsAddon().getForObject(...); }
To make requests using OAuth 2.0, the add-on must request the ACT_AS_USER scope in its add-on descriptor.
To obtain a RestTemplate using OAuth 2.0 authentication, use authenticatedAsHostActor() or
authenticatedAs(AtlassianHostUser):
@Autowired private AtlassianHostRestClients restClients; public void makeRequest() { restClients.authenticatedAsHostActor().getForObject(...); }
| Modifier and Type | Method and Description |
|---|---|
OAuth2RestTemplate |
authenticatedAs(AtlassianHostUser hostUser)
Returns a
RestTemplate for making requests to the given Atlassian host using OAuth 2.0 JWT Bearer Token
authentication. |
RestTemplate |
authenticatedAsAddon()
Returns a
RestTemplate for making requests to Atlassian hosts using JWT authentication. |
OAuth2RestTemplate |
authenticatedAsHostActor()
Returns a
RestTemplate for making requests to the currently authenticated Atlassian host using
OAuth 2.0 JWT Bearer Token authentication. |
String |
createJwt(HttpMethod method,
URI uri)
Creates a JSON Web Token for use when the
RestTemplate provided by authenticatedAsAddon()
cannot be used to make requests to Atlassian hosts, such as when using Jersey. |
RestTemplate authenticatedAsAddon()
RestTemplate for making requests to Atlassian hosts using JWT authentication.
The principal of the request is the add-on.
During processing of a request from an Atlassian host, relative URLs can be used to make requests to the current host.
When a request is made to an absolute URL, the request URL is used to resolve the destination Atlassian host. If no host matches, the request is not signed.
String createJwt(HttpMethod method, URI uri)
RestTemplate provided by authenticatedAsAddon()
cannot be used to make requests to Atlassian hosts, such as when using Jersey.
WebTarget webTarget = ClientBuilder.newClient().target(host.getBaseUrl()).path(...); String jwt = atlassianHostRestClients.createJwt(HttpMethod.GET, webTarget.getUri()); Response response = webTarget.request().header("Authorization", "JWT " + jwt).get();
NOTE: Whenever possible, use of authenticatedAsAddon() is recommended over use of
this method.
The created JWT is restricted for use with the given HTTP method and request URL.
The request URL is used to resolve the destination Atlassian host. If no host matches, an
IllegalArgumentException is thrown.
method - the HTTP method of the request to be authenticateduri - the absolute URL of the request to be authenticatedIllegalArgumentException - if the URL did not have the base URL of any installed hostauthenticatedAsAddon()OAuth2RestTemplate authenticatedAsHostActor()
RestTemplate for making requests to the currently authenticated Atlassian host using
OAuth 2.0 JWT Bearer Token authentication. The principal of the request is the currently authenticated user.
On first invocation, the OAuth2RestTemplate will request an access token from Atlassian's
authorization server. The access token will then be cached for further use. Once the token has expired, a new
token will be fetched transparently. Additionally, the OAuth2RestTemplate for a particular host user
is cached between requests using
Spring Caching.
authenticatedAs(AtlassianHostUser)OAuth2RestTemplate authenticatedAs(AtlassianHostUser hostUser)
RestTemplate for making requests to the given Atlassian host using OAuth 2.0 JWT Bearer Token
authentication. The principal of the request is the given user.
On first invocation, the OAuth2RestTemplate will request an access token from Atlassian's
authorization server. The access token will then be cached for further use. Once the token has expired, a new
token will be fetched transparently. Additionally, the OAuth2RestTemplate for a particular host user
is cached between requests using
Spring Caching.
authenticatedAsHostActor()Copyright © 2018 Atlassian. All rights reserved.