MegaTracker cloud service authentication
This article explains how to specify the authentication method when using MegaTracker with cloud services.
Before you begin
Using API key and API secret authentication
This approach applies to traditional key-pair verification. You need to use APIKeyAccessData to construct the access object in MegaTrackerConfigs.
const apiKeyAccess = new mega.APIKeyAccessData(
settings.MegaTrackerAppID, // Mega positioning service AppID
settings.MegaTrackerServerAddress, // Mega positioning service address
settings.EasyARAPIKey, // APIKey string
settings.EasyARAPISecret // APISecret string
);
const megaTrackerConfigs: easyar.MegaTrackerConfigs = {
access: apiKeyAccess
};
const sessionConfigs: easyar.SessionConfigs = {
megaTrackerConfigs: megaTrackerConfigs,
licenseKey: settings.EasyARLicenseKey
};
session = megaComponent.createSession(sessionConfigs);
In this example, we first create APIKeyAccessData using the cloud positioning library
appId, cloud serviceserverAddress, cloud serviceapiKeyandapiSecretfrom the configuration.Then use the created APIKeyAccessData to create MegaTrackerConfigs. This indicates that API key and API secret authentication will be used.
Using APIToken authentication
If you can update and distribute APIToken periodically (every few minutes or hours) via a server, this approach avoids directly signing location requests with APISecret, offering higher security. For updating APIToken, refer to Token creation and usage methods.
You can set a timer on the frontend to update it based on the Token's validity period.
First, create TokenAccessData using the Mega location library AppID and location service address from your settings.
Then use the created TokenAccessData to build MegaTrackerConfigs.
Next, create SessionConfigs using MegaTrackerConfigs and the licenseKey from your configuration.
Finally, create the session using the createSession(sessionConfigs) method of the EasyARMegaComponent attached to your xr-frame scene.
When the Token expires, you must call updateToken(apiToken) to update it; otherwise, the Mega service will become unavailable, and the status in localization results will always be ApiTokenExpired.
const tokenAccess = new mega.TokenAccessData(
settings.MegaTrackerAppID, // Mega location service AppID
settings.MegaTrackerServerAddress, // Mega location service address
"your_api_token" // APIToken string
);
const megaTrackerConfigs: easyar.MegaTrackerConfigs = {
access: tokenAccess
};
const sessionConfigs: easyar.SessionConfigs = {
megaTrackerConfigs: megaTrackerConfigs,
licenseKey: settings.EasyARLicenseKey
};
session = megaComponent.createSession(sessionConfigs);
This example demonstrates how to create MegaTrackerConfigs using TokenAccessData, and use this MegaTrackerConfigs to create a session for
APITokenauthentication.