public class HereAccount extends Object
To use your provided credentials.properties to get a one-time use token:
// use your provided credentials.properties
TokenEndpoint tokenEndpoint = HereAccount.getTokenEndpoint(
ApacheHttpClientProvider.builder().build(),
new OAuth1ClientCredentialsProvider.FromFile(new File("credentials.properties")));
String hereAccessToken = tokenEndpoint.requestToken(
new ClientCredentialsGrantRequest()).getAccessToken();
// use hereAccessToken on requests until expires...
Specific use cases currently supported include:
// set up url, accessKeyId, and accessKeySecret.
TokenEndpoint tokenEndpoint = HereAccount.getTokenEndpoint(
ApacheHttpClientProvider.builder().build(),
new OAuth1ClientCredentialsProvider(url, accessKeyId, accessKeySecret));
String hereAccessToken = tokenEndpoint.requestToken(
new ClientCredentialsGrantRequest()).getAccessToken();
// use hereAccessToken on requests until expires...
// set up url, accessKeyId, and accessKeySecret.
TokenEndpoint tokenEndpoint = HereAccount.getTokenEndpoint(
ApacheHttpClientProvider.builder().build(),
new OAuth1ClientCredentialsProvider(url, accessKeyId, accessKeySecret));
// call this once and keep a reference to freshToken, such as in your beans
Fresh<AccessTokenResponse> freshToken = tokenEndpoint.requestAutoRefreshingToken(
new ClientCredentialsGrantRequest());
// using your reference to freshToken, for each request, just ask for the token
// the same hereAccessToken is returned for most of the valid time; but as it nears
// expiry the returned value will change.
String hereAccessToken = freshToken.get().getAccessToken();
// use hereAccessToken on your request...
Convenience ClientCredentialsProvider implementations are also available to
automatically pull the url, accessKeyId, and accessKeySecret
from a Properties object or properties file:
// setup url, accessKeyId, and accessKeySecret as properties in credentials.properties
TokenEndpoint tokenEndpoint = HereAccount.getTokenEndpoint(
ApacheHttpClientProvider.builder().build(),
new OAuth1ClientCredentialsProvider.FromFile(new File("credentials.properties")));
// choose
// tokenEndpoint.requestToken(new ClientCredentialsGrantRequest());
// or
// tokenEndpoint.requestAutoRefreshingToken(new ClientCredentialsGrantRequest());
The above examples use the JavaHttpProvider. Another example HttpProvider from this project below uses pure-Java.
// create a Java HttpProvider
HttpProvider httpProvider = JavaHttpProvider.builder().build();
// use httpProvider
| Modifier and Type | Method and Description |
|---|---|
static TokenEndpoint |
getTokenEndpoint(HttpProvider httpProvider,
ClientAuthorizationRequestProvider clientAuthorizationRequestProvider)
Get the ability to run various Token Endpoint API calls to the
HERE Account Authorization Server.
|
static TokenEndpoint |
getTokenEndpoint(HttpProvider httpProvider,
ClientAuthorizationRequestProvider clientAuthorizationRequestProvider,
Serializer serializer)
Deprecated.
use
HereAccessTokenProvider.builder() instead |
static TokenEndpoint |
getTokenEndpoint(HttpProvider httpProvider,
ClientCredentialsProvider clientCredentialsProvider)
Deprecated.
Use of getTokenEndpoint(HttpProvider httpProvider, ClientAuthorizationRequestProvider clientAuthorizationRequestProvider) is suggested
This method is solely for backward compatibility
Get the ability to run various Token Endpoint API calls to the
HERE Account Authorization Server.
See OAuth2.0
Obtaining Authorization.
The returned
TokenEndpoint exposes an abstraction to make calls
against the OAuth2 token endpoint identified by the given client credentials
provider. In addition, all calls made against the returned endpoint will
automatically be injected with the given client credentials. |
public static TokenEndpoint getTokenEndpoint(HttpProvider httpProvider, ClientCredentialsProvider clientCredentialsProvider)
TokenEndpoint exposes an abstraction to make calls
against the OAuth2 token endpoint identified by the given client credentials
provider. In addition, all calls made against the returned endpoint will
automatically be injected with the given client credentials.httpProvider - the HTTP-layer provider implementationclientCredentialsProvider - identifies the token endpoint URL and
client credentials to be injected into requestsTokenEndpoint representing access for the provided clientpublic static TokenEndpoint getTokenEndpoint(HttpProvider httpProvider, ClientAuthorizationRequestProvider clientAuthorizationRequestProvider)
TokenEndpoint exposes an abstraction to make calls
against the OAuth2 token endpoint identified by the given client credentials
provider. In addition, all calls made against the returned endpoint will
automatically be injected with the given client credentials.httpProvider - the HTTP-layer provider implementationclientAuthorizationRequestProvider - identifies the token endpoint URL and
client credentials to be injected into requestsTokenEndpoint representing access for the provided client@Deprecated public static TokenEndpoint getTokenEndpoint(HttpProvider httpProvider, ClientAuthorizationRequestProvider clientAuthorizationRequestProvider, Serializer serializer)
HereAccessTokenProvider.builder() insteadHereAccessTokenProvider.builder() instead.httpProvider - the HTTP-layer provider implementationclientAuthorizationRequestProvider - identifies the token endpoint URL and
client credentials to be injected into requestsserializer - the Serializer to useTokenEndpoint representing access for the provided clientCopyright © 2022 HERE Europe B.V. All Rights Reserved.