Примеры кода для API регистрации токенов управления Chrome

Для ознакомления с функциями API посетите страницу Chrome Management Enrollment Tokens API .

Все запросы, представленные на этой странице, используют следующие переменные:

  • $TOKEN - токен OAuth 2.0
  • $CUSTOMER - ID клиента или буквальное значение my_customer

Создайте токен регистрации.

To create a new enrollment token for a browser device, use the /enrollmentTokens endpoint with HTTP POST . You can optionally specify an enrollmentTokenId query parameter to assign a custom token ID.

Запрос

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens" \
  -d '{
    "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER",
    "orgUnitId": "03ph8a2z3v"
  }'

Ответ

{
  "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId>",
  "tokenPermanentId": "<tokenPermanentId>",
  "token": "<tokenValue>",
  "customerId": "<customerId>",
  "orgUnitId": "03ph8a2z3v",
  "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
  "createTime": "2024-04-23T22:00:00.000Z",
  "creatorId": "user@example.com",
  "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
}

Получите токен регистрации

Для получения отдельного токена регистрации используйте конечную точку /enrollmentTokens/{token_permanent_id} с HTTP GET .

Запрос

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens/<tokenPermanentId>"

Ответ

{
  "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId>",
  "tokenPermanentId": "<tokenPermanentId>",
  "token": "<tokenValue>",
  "customerId": "<customerId>",
  "orgUnitId": "03ph8a2z3v",
  "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
  "createTime": "2024-04-23T22:00:00.000Z",
  "creatorId": "user@example.com",
  "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
}

Токены для регистрации в списке

To list enrollment tokens, use the /enrollmentTokens endpoint with HTTP GET . You can control pagination using pageSize (maximum and default 100) and pageToken parameters. Specify a filter to narrow down results.

Примеры запросов с фильтрацией

# Filter by token state
filter=token_state=ACTIVE

# Filter by Organizational Unit path
filter=org_unit_path=/Marketing

# Filter by Organizational Unit path containing spaces
filter=org_unit_path='/Browser Management'

# Filter by Organizational Unit ID
filter=org_unit_id=03ph8a2z3v

# Filter by token state, Organizational Unit path, and device type
filter=token_state=ACTIVE AND org_unit_path=/Marketing AND device_type=CHROME_BROWSER

Запрос

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens?pageSize=2&filter=token_state=ACTIVE"

Ответ

{
  "enrollmentTokens": [
    {
      "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId1>",
      "tokenPermanentId": "<tokenPermanentId1>",
      "token": "<tokenValue1>",
      "customerId": "<customerId>",
      "orgUnitId": "03ph8a2z3v",
      "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
      "createTime": "2024-04-23T22:00:00.000Z",
      "creatorId": "user1@example.com",
      "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
    },
    {
      "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId2>",
      "tokenPermanentId": "<tokenPermanentId2>",
      "token": "<tokenValue2>",
      "customerId": "<customerId>",
      "orgUnitId": "03ph8a2z3v",
      "state": "ENROLLMENT_TOKEN_STATE_ACTIVE",
      "createTime": "2024-04-23T21:30:00.000Z",
      "creatorId": "user2@example.com",
      "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
    }
  ],
  "nextPageToken": "<nextPageToken>"
}

Отозвать токен регистрации

Для отзыва токена регистрации используйте конечную точку /enrollmentTokens/{token_permanent_id}:revoke с HTTP POST запросом.

Запрос

  curl -X POST \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  "https://chromemanagement.googleapis.com/v1/customers/$CUSTOMER/enrollmentTokens/<tokenPermanentId>:revoke" \
  -d '{}'

Ответ

{
  "name": "customers/<customerId>/enrollmentTokens/<tokenPermanentId>",
  "tokenPermanentId": "<tokenPermanentId>",
  "token": "<tokenValue>",
  "customerId": "<customerId>",
  "orgUnitId": "03ph8a2z3v",
  "state": "ENROLLMENT_TOKEN_STATE_REVOKED",
  "createTime": "2024-04-23T22:00:00.000Z",
  "revokeTime": "2024-04-24T10:15:00.000Z",
  "creatorId": "user@example.com",
  "revokerId": "admin@example.com",
  "tokenType": "ENROLLMENT_TOKEN_TYPE_CHROME_BROWSER"
}