Samsung Knox API and Tooling

website·Indexed 29 days ago

https://redredgroup.github.io/samsungknox/

Documentation for Samsung Knox integration, featuring the Knox API for Knox Configure device and profile management, the Knox Token Library for generating signed API access tokens and client identifiers, and the Knox Fastlane Plugin for application deployment.

Tokens
8.3K
Snippets
32
Records
62
Agent score
75%

What's inside Samsung Knox

  1. Overview of SamsungKnox Token Library

    The @redredgroup/samsungknox-token-library (also referenced as knox-token-library-js) is a server-side JavaScript utility designed to help developers generate and sign the credentials required to interact with Knox Cloud Services APIs. It specifically handles the creation of signed ClientIdentifiers and signed Api Access Tokens.
  2. Overview of the Knox Fastlane Plugin

    The Knox Fastlane Plugin is a Fastlane extension designed to automate the upload of Android applications (such as APKs) to the Knox Configure Library. This allows developers to integrate the upload to the SamsungKnox server directly into their build and release workflow.

    Critical Constraints:

    • Platform Support: This plugin currently only works on Android. Do not use it on iOS.
    • Release Status: The plugin is not yet officially released; some features may be unstable or missing.
  3. Retrieve KnoxConfigure profile details

    Use the getProfileDetails method from the kcProfile module of the KnoxInstance to fetch detailed information about a specific KnoxConfigure profile. You must provide the profileId within the args object.
    import { KnoxInstance } from '@redredgroup/samsungknox-api';
    
    const instance = new KnoxInstance({
      region: 'YOUR_KNOX_REGION', // e.g., 'EU'
      knoxAccessToken: 'YOUR_JWT_TOKEN',
    });
    
    const getProfileDetail = await instance.kcProfile.getProfileDetails({
      args: {
        profileId: 'YOUR_PROFILE_ID',
      },
    });
    
    console.log(getProfileDetail);
  4. Generate a signed API access token using KnoxTokenUtility

    Use the generateSignedAccessTokenJWT method from the knoxTokenLibrary (KnoxTokenUtility class) to sign an API access token using the primary key from a downloaded Knox credential file. This is required to authenticate requests to Knox Cloud Services.
    const { accessToken } = await knoxTokenLibrary.generateSignedAccessTokenJWT({
      credential: {
        // Provide the path to the credential.json file downloaded from the Knox API portal
        path: 'credential.json',
        // Alternatively, provide the key directly
        key: 'credential',
      },
      // The raw api AccessToken returned by the Knox Cloud Services generateAccessToken API
      accessToken: 'my-access-token',
    });
    
    console.log(accessToken);
  5. Prerequisites for using SamsungKnox Token Library

    Before using the library to generate tokens, you must obtain the following from the Samsung Knox Admin Portal:

    1. A Knox Credential file (credential.json).
    2. A Client Identifier (api-key) generated for accessing Knox Cloud Services APIs.

    Ensure that your keys have Cloud API privileges. If permissions are missing, you may need to request them via the Samsung Knox Admin Portal.

  6. Validate a KnoxConfigure license

    To validate a KnoxConfigure license, use the validateLicense method provided by the kcLicense property of a KnoxInstance. This requires a valid license key and license name, along with the appropriate Knox region and access token.
    import { KnoxInstance } from '@redredgroup/samsungknox-api';
    
    const instance = new KnoxInstance({
      region: 'YOUR_KNOX_REGION', // e.g., 'EU'
      knoxAccessToken: 'YOUR_JWT_TOKEN', // Your X-KNOX-APITOKEN
    });
    
    const validateLicense = await instance.kcLicense.validateLicense({
      args: {
        licenseKey: 'YOUR_LICENSE_KEY',
        licenseName: 'YOUR_LICENSE_NAME',
      },
    });
    
    console.log(validateLicense);
  7. Upload a public app from Play Store or Galaxy Store using KnoxConfigure

    To upload a public application from the Google Play Store or Samsung Galaxy Store into KnoxConfigure, use the uploadAPublicAppFromPlayStoreOrGalaxyStore method provided by the kcContentManagementApplication module of the KnoxInstance class. This requires a valid Knox API token and the specific region of the Knox instance.
    import { KnoxInstance } from '@redredgroup/samsungknox-api';
    
    const instance = new KnoxInstance({
      region: 'YOUR_KNOX_REGION', // e.g., 'EU'
      knoxAccessToken: 'YOUR_JWT_TOKEN', // Your X-KNOX-APITOKEN
    });
    
    const result = await instance.kcContentManagementApplication.uploadAPublicAppFromPlayStoreOrGalaxyStore({
      args: {
        name: 'YOUR_APP_NAME',
        platform: 'ANDROID',
        source: 'GOOGLE_PLAY_STORE', // Use 'GOOGLE_PLAY_STORE' or 'GALAXY_STORE'
      },
    });
    
    console.log(result);
  8. Register a KnoxConfigure license

    To register a license for KnoxConfigure, use the registerLicense method provided by the kcLicense property of a KnoxInstance. You must provide a valid license key and a name for the license.
    import { KnoxInstance } from '@redredgroup/samsungknox-api';
    
    const instance = new KnoxInstance({
      region: 'YOUR_KNOX_REGION', // e.g., 'EU'
      knoxAccessToken: 'YOUR_JWT_TOKEN', // Your X-KNOX-APITOKEN
    });
    
    const registerLicense = await instance.kcLicense.registerLicense({
      args: {
        licenseKey: 'YOUR_LICENSE_KEY',
        licenseName: 'YOUR_LICENSE_NAME',
      },
    });
    
    console.log(registerLicense);
  9. Delete devices from Knox Configure

    Use the deleteDevice method from the kcDevice module to remove devices from Knox Configure.

    Warning: Deleting a device is a destructive action. To re-enroll a deleted device, you must contact your partner or Samsung Knox; manual enrollment of items like licenses is not possible.

    Input Parameters:

    • args: An object containing deviceIds (an array of strings representing the IDs of the devices to be deleted). Required.
    • region: The Knox region (e.g., 'EU').
    • knoxAccessToken: Your X-KNOX-APITOKEN (JWT token).

    Output: The response returns the total number of devices processed, including the count of successful deletions, unsuccessful attempts, and pending devices.

    import { KnoxInstance } from '@redredgroup/samsungknox-api';
    
    const instance = new KnoxInstance({
      region: 'YOUR_KNOX_REGION', // e.g., 'EU'
      knoxAccessToken: 'YOUR_JWT_TOKEN',
    });
    
    const kcDeleteDevice = await instance.kcDevice.deleteDevice({
      args: {
        deviceIds: ['YOUR_DEVICE_ID1'],
      },
    });
    
    console.log(kcDeleteDevice);
  10. Unassign a profile from devices using KnoxConfigure

    To unassign a profile from one or more devices in KnoxConfigure, use the unassignProfileDevices method provided by the kcDevice module of the KnoxInstance. This requires a list of device IDs and a valid Knox access token.
    import { KnoxInstance } from '@redredgroup/samsungknox-api';
    
    const instance = new KnoxInstance({
      region: 'YOUR_KNOX_REGION', // e.g., 'EU'
      knoxAccessToken: 'YOUR_JWT_TOKEN',
    });
    
    const kcUnassignProfileDevice = await instance.kcDevice.unassignProfileDevices({
      args: {
        deviceIds: ['YOUR_DEVICE_ID1', 'YOUR_DEVICE_ID2'],
      },
    });
    
    console.log(kcUnassignProfileDevice);
  11. Upload media files to KnoxConfigure CMS

    Use the uploadMediaFileContentInCms method from the kcContentManagementAsset module to upload media files (such as .txt, .png, .pdf, or .ogg) to the KnoxConfigure CMS. This requires a valid Knox access token and the specific Knox region.
    import { KnoxInstance } from '@redredgroup/samsungknox-api';
    
    const instance = new KnoxInstance({
      region: 'YOUR_KNOX_REGION', // e.g., 'EU'
      knoxAccessToken: 'YOUR_JWT_TOKEN',
    });
    
    const uploadMediaFileContentInCms = await instance.kcContentManagementAsset.uploadMediaFileContentInCms({
      args: {
        file: 'YOUR_FILE_PATH', // Path to the file (e.g., .txt, .png, .pdf, .ogg)
      },
    });
    
    console.log(uploadMediaFileContentInCms);