How to authenticate to the HERE platform
You can use an access token to authenticate to the HERE platform and start working with HERE Data SDK for Typescript. You can receive it using a default token provider, local authorization, or project authentication.
Note
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.
To get an access token:
- Create your app and get your API key.
For instructions, see the Manage apps section in the Identity and Access Management Developer Guide.
- Get your platform credentials.
For instructions, see the Register your application section in the Identity and Access Management Developer Guide.
You get the credentials.properties file.
-
Set your credentials in one of the following ways:
-
(For Node.js only) Get your credentials from the file using the
loadCredentialsFromFilehelper method.const credentials = loadCredentialsFromFile("Path"); -
(For browser and Node.js) Set credentials manually using the here.access.key.іd and here.access.key.secret from the
credentials.propertiesfile.const credentials = { accessKeyId: "replace-with-your-access-key-id", accessKeySecret: "replace-with-your-access-key-secret", };
-
-
Import the
requestTokenmethod and theUserAuthmodule from theolp-sdk-authenticationmodule.import { UserAuth, requestToken } from "@here/olp-sdk-authentication"; -
Create the
UserAuthinstance and, if needed, specify the token expiration time in one of the following ways:
Note
The token expiration time parameter is optional. The default value is 24 hours. If you want to change it, specify the new time in seconds. The token expiration time should be equal to or more than zero. Ignored if it is zero or greater than the default expiration time supported by the access token endpoint.
-
For token authentication, specify the
tokenRequestermethod, your credentials, and the token expiration time.const userAuth = new UserAuth({ tokenRequester: requestToken, credentials: credentials, expiresIn?: number; }); -
To authenticate with local authorization, specify the environment in which you work, your credentials, the
tokenRequestermethod, and the token expiration time.
Note
Depending on the environment that you use, specify one of the following parameters:
envorcustomUrl.
const userAuth = new UserAuth({
env: "here | here-dev | here-cn | here-cn-dev",
customUrl: "http://YourCustomEnvironment",
credentials: credentials,
tokenRequester: requestToken,
expiresIn?: number;
});- For project authentication, specify the
tokenRequestermethod, your project name, credentials, and the token expiration time.const userAuth = new UserAuth({ tokenRequester: requestToken, scope: "your-project-name". credentials: credentials, expiresIn?: number; });
-
Get the OAuth 2.0 token from the HERE platform using the
getTokenmethod.const token: string = await userAuth.getToken();
You can now use the access token to create the OlpClientSettings object and work with layers. For instructions, see the related section.
Updated 10 days ago