To authenticate to the HERE platform and start working with HERE Data SDK for C++, you need to get an access token. You can receive it using a default token provider, project authentication, or federated credentials.
For instructions, see the OAuth tokens section in the Identity & Access Management Developer Guide.
Keep your credentials secure and do not disclose them. Make sure that your credentials are not stored in a way that enables others to access them.
-
Get your platform credentials.
For instructions, see the Register your application section in the Identity & Access Management Developer Guide.
You get the
credentials.properties
file. -
Initialize the authentication settings using the here.access.key.іd and here.access.key.secret from the
credentials.properties
file askKeyId
andkKeySecret
respectively.You can also retrieve your credentials from the
credentials.properties
file using theReadFromFile
method. For more information, see the related API documentation.olp::authentication::Settings settings({kKeyId, kKeySecret}); settings.task_scheduler = task_scheduler; settings.network_request_handler = http_client;
-
Set up the
AuthenticationSettings
object with a default token provider.olp::client::AuthenticationSettings auth_settings; auth_settings.token_provider = olp::authentication::TokenProviderDefault(std::move(settings));
You get an access token.
You can use the AuthenticationSettings
object to create the OlpClientSettings
object. For more information, see the related section in the Developer Guide.
-
Get your platform credentials.
For instructions, see the Register your application section in the Identity & Access Management Developer Guide.
-
Initialize the
AuthenticationCredentials
class using the here.access.key.іd and here.access.key.secret from thecredentials.properties
file askKeyId
andkKeySecret
respectively.You can also retrieve your credentials from the
credentials.properties
file using theReadFromFile
method. For more information, see the related API documentation.olp::authentication::AuthenticationCredentials credentials(kKeyId, kKeySecret);
-
Create an authentication client.
olp::authentication::AuthenticationSettings auth_client_settings; auth_client_settings.task_scheduler = task_scheduler; auth_client_settings.network_request_handler = http_client; olp::authentication::AuthenticationClient client(auth_client_settings);
-
Create the
SignInProperties
object with your project ID.olp::authentication::AuthenticationClient::SignInProperties signin_properties; signin_properties.scope = "<project ID>";
-
Call the
SignInClient
API on the previously createdclient
object.client.SignInClient( credentials, signin_properties, [](olp::authentication::Response<olp::authentication::SignInResult> response) { // Handle the response });
You get an access token.
You can use the AuthenticationSettings
object to create the OlpClientSettings
object. For more information, see the related section in the Developer Guide.
-
Get your platform credentials.
For instructions, see the Register your application section in the Identity & Access Management Developer Guide.
You get the
credentials.properties
file. -
Initialize the
AuthenticationCredentials
class using the here.access.key.іd and here.access.key.secret from thecredentials.properties
file askKeyId
andkKeySecret
respectively.You can also retrieve your credentials from the
credentials.properties
file using theReadFromFile
method. For more information, see the related API documentation.olp::authentication::AuthenticationCredentials credentials(kKeyId, kKeySecret);
-
Create an authentication client's settings.
olp::authentication::AuthenticationSettings auth_client_settings; auth_client_settings.task_scheduler = task_scheduler; auth_client_settings.network_request_handler = http_client;
-
Get your federated (Facebook or ArcGIS) properties.
You should have at least your federated access token. For the complete list of federated properties, see the related documentation.
-
Initialize your federated properties.
olp::authentication::AuthenticationClient::FederatedProperties properties; properties.access_token = "your-access-token";
-
Create your own token provider using the authentication client's settings created in step 3, your federated credentials.
You can call your custom token provider form different threads.
auto token = std::make_shared<olp::client::OauthToken>(); olp::client::AuthenticationSettings auth_settings; auth_settings.token_provider = [token, auth_client_settings, credentials, properties](olp::client::CancellationContext context) -> olp::client::OauthTokenResponse { if (context.IsCancelled()) { return olp::client::ApiError::Cancelled(); } if (!token->GetAccessToken().empty() && std::chrono::system_clock::to_time_t( std::chrono::system_clock::now()) >= token->GetExpiryTime()) { return *token; } std::promise<olp::authentication::AuthenticationClient::SignInUserResponse> token_promise; auto callback = [&token_promise]( olp::authentication::AuthenticationClient::SignInUserResponse response) { token_promise.set_value(std::move(response)); }; olp::authentication::AuthenticationClient client(auth_client_settings); client.SignInFacebook(credentials, properties, callback); auto response = token_promise.get_future().get(); if (!response) { return response.GetError(); } (*token) = olp::client::OauthToken(response.GetResult().GetAccessToken(), response.GetResult().GetExpiresIn()); return *token; };
You get an access token. By default, it expires in 24 hours. To continue working with the HERE platform after your token expires, generate a new access token.
You can use the AuthenticationSettings
object to create the OlpClientSettings
object. For more information, see the related section in the Developer Guide.