Share a scene

Updated at:

Trajectory Analysis lets you share created scenes with other users, granting them permission to view or control device status. This topic describes how to share a scene.

Prerequisites

A scene has been created. For more information, see Create a scene.

Procedure

  1. Log in to the IoT Platform console. In the left-side navigation pane, choose value-added services > Device Location Service.

  2. On the IoT Device Location Service page, click Trajectory Analysis.

  3. Select a created scene. In the upper-right corner of the map, click Share and configure the parameters. In the Share dialog box, you can also select Hide the scene toolbar to remove the toolbar from the shared scene.

    Parameter

    Description

    Test link

    A login-free link for testing access to the scene.

    Note

    To test the link, click Copy and open it in your browser to access the scene directly.

    URL

    The login-free URL for the shared scene. This URL is generated by IoT Platform in the format https://gis.aliyun-iot-share.com/auth/gis/{hashToken}/9f36af685****7efaadbd8352f5233a1, where 9f36af685****7efaadbd8352f5233a1 is the scene identifier.

    Note

    The {hashToken} placeholder in the URL must be replaced to enable login-free access. For more information, see Generate a login-free URL.

    Token

    The unique credential used to generate the hashToken. Keep this token secure. If leaked, your scenes could be exposed to unauthorized access.

    Session validity

    Includes two options:

    • 10 hours: The login session expires after 10 hours.

    • Permanent: The login-free URL is permanently valid.

      Important

      A permanently valid URL remains accessible indefinitely. Be aware of the security risks before selecting this option.

  4. Click OK to apply the sharing settings.

Generate a login-free URL

This section explains how to generate a login-free URL from a token using an open-source algorithm and provides code examples in several programming languages.

  1. In the Share dialog box, copy the URL and Token.

    Example:

    • URL: https://gis.aliyun-iot-share.com/auth/gis/{hashToken}/9f36af685****7efaadbd8352f5233a1

    • Token: hSc3****

  2. Perform bcrypt hashing on the token to generate a midToken.

    For example, performing bcrypt hashing on the example token hSc3**** returns the following result:

    $2a$10$td0GQDWPLnE98pRHaFB/n.FYG5****TZ4uXVPVw7f3omKUFOHtj.K

    Note

    Due to the nature of the bcrypt algorithm, the hashing operation produces a different midToken each time.

  3. Perform Base64 encoding on the midToken from the bcrypt hashing to generate a hashToken.

    Performing Base64 encoding on the example midToken from the previous step returns the following result:

    JDJhJDEwJHRkMEdRRFdQTG5FOThwUkhhRkIvbi5GWUc1OTc5QVRaNHVYVlBWdzdmM29tS1VGT0h0ai5L

  4. Replace the {hashToken} placeholder in the URL from Step 1 with the encoded result from Step 3 to generate the final login-free URL.

    The resulting login-free URL:

    https://gis.aliyun-iot-share.com/auth/gis/JDJhJDEwJHRkMEdRRFdQTG5FOThwUkhhRkIvbi5GWUc1OTc5QVRaNHVYVlBWdzdmM29tS1VGT0h0ai5L/9f36af685****7efaadbd8352f5233a1

    Note

    If a session expires or you need to update a permanent link, obtain a new token and repeat these steps to generate a new hashToken.

The following examples show how to generate a login-free URL from a token in different programming languages.

  • Java implementation

    import org.apache.commons.codec.binary.Base64;
    import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    public class TokenUtil {
        private static final BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        public static String encodeBase64(String encodedStr)
        {
            byte[] debytes = Base64.encodeBase64(encodedStr.getBytes());
            return new String(debytes);
        }
        public static String encodeBCrypt(String token){
            return encoder.encode(token);
        }
        public static void main(String[] args) {
            String token = "123456"; // The token from the page.
            String midToken = TokenUtil.encodeBCrypt(token);// Generate the intermediate token.
            String hashToken = TokenUtil.encodeBase64(midToken); // Generate the hashToken.
            String URL = "https://gis.aliyun-iot-share.com/auth/gis/" + hashToken + "/xxx";
            System.out.println("Your shareable URL is: " + URL);
        }
    }
  • Node.js implementation

    var bcrypt = require('bcryptjs');
    const saltRounds = 10;
    const salt = bcrypt.genSaltSync(saltRounds);
    const token = "123456" // The token from the page.
    const midToken = bcrypt.hashSync(token, salt);// Generate the intermediate token.
    const midTokenBuf = new Buffer(midToken);
    const hashToken = midTokenBuf.toString('base64');// Generate the hashToken.
    const url = "https://gis.aliyun-iot-share.com/auth/gis/" + hashToken + "/xxx";
    console.info("Your shareable URL is: " + url)
  • Python implementation (Python 3.0)

    # coding=utf-8
    import bcrypt
    import base64
    if __name__ == '__main__':  # Program start from here
        token = b"123456" # The token from the page.
        midToken = bcrypt.hashpw(token, bcrypt.gensalt(prefix=b"2a")) # Generate the intermediate token.
        hashToken = base64.b64encode(midToken).decode()# Generate the hashToken.
        url = "https://gis.aliyun-iot-share.com/auth/gis/" + hashToken + "/xxx"
        print ("Your shareable URL is: " + url)