Devices API 설정
이 페이지에서는 Cloud ID 기기 API를 설정하는 방법을 설명합니다. Devices API를 사용하여 관리자를 대신하여 리소스(예: Google 그룹 관리)를 프로그래매틱 방식으로 프로비저닝할 수 있습니다.
API 사용 설정 및 사용자 인증 정보 설정
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Cloud Identity API. Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
- 
    
    
      In the Google Cloud console, on the project selector page, select or create a Google Cloud project. Roles required to select or create a project - Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
- 
      Create a project: To create a project, you need the Project Creator
      (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
 
- 
  
    Verify that billing is enabled for your Google Cloud project. 
- 
  
  
    
      Enable the Cloud Identity API. Roles required to enable APIs To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
- 서비스 계정을 만들려면 다음을 수행합니다. - Google Cloud 콘솔에서 IAM 서비스 계정 페이지로 이동합니다. 
- 서비스 계정 만들기를 클릭합니다. 
- 서비스 계정 세부정보에서 서비스 계정의 이름, ID, 설명을 입력한 다음 만들고 계속하기를 클릭합니다. 
- 선택사항: 이 서비스 계정에 프로젝트에 대한 액세스 권한 부여에서 서비스 계정에 부여할 IAM 역할을 선택합니다. 
- 계속을 클릭합니다. 
- 선택사항: 사용자에게 이 서비스 계정에 대한 액세스 권한 부여에서 서비스 계정을 사용하고 관리할 수 있는 사용자 또는 그룹을 추가합니다. 
- 완료를 클릭합니다. 
 
- 서비스 계정이 도메인 전체 위임을 사용하여 Devices API에 액세스하도록 하려면 서비스 계정에 도메인 전체 위임 설정의 안내를 따르세요. 
- 서비스 계정 키를 만들고 다운로드하려면 다음 단계를 따르세요. - 생성한 서비스 계정의 이메일 주소를 클릭합니다.
- 키 탭을 클릭합니다.
- 키 추가 드롭다운 목록에서 새 키 만들기를 선택합니다.
- 만들기를 클릭합니다. - 새 공개 키 및 비공개 키 쌍이 포함된 JSON 형식의 사용자 인증 정보 파일이 생성되어 컴퓨터에 다운로드됩니다. 파일에 키의 유일한 사본이 포함되어 있습니다. 안전하게 보관할 책임은 사용자에게 있습니다. 키 쌍을 분실한 경우 새 키 쌍을 생성해야 합니다. 
 
- SERVICE_ACCOUNT_CREDENTIAL_FILE: 이 문서 앞부분에서 만든 서비스 계정 키 파일
- USER: 서비스 계정이 가장하는 사용자
- SERVICE_ACCOUNT_CREDENTIAL_FILE: 이 문서 앞부분에서 만든 서비스 계정 키 파일
- USER: 서비스 계정이 가장하는 사용자
도메인 전체 위임이 있는 서비스 계정을 사용하여 API 액세스 설정
이 섹션에서는 서비스 계정을 만들어 Google Workspace 리소스에 액세스하는 방법을 설명합니다. 서비스 계정을 사용하여 Devices API에 직접 인증하는 것은 지원되지 않으므로 이 방법을 사용해야 합니다.
서비스 계정을 만들고 도메인 전체 위임에 맞게 구성
서비스 계정을 만들고 서비스 계정 키를 다운로드하려면 다음 단계를 따르세요.
로그 항목 검토
로그 항목을 검토할 때 감사 로그에는 모든 서비스 계정 작업이 사용자가 시작한 것으로 표시됩니다. 이는 서비스 계정에서 관리자 사용자를 가장할 수 있도록 도메인 전체 위임이 작동하기 때문입니다.
사용자 인증 정보 초기화
코드에서 사용자 인증 정보를 초기화할 때 사용자 인증 정보의 with_subject()를 호출하여 서비스 계정이 작동할 이메일 주소를 지정합니다.
예를 들면 다음과 같습니다.
Python
credentials = service_account.Credentials.from_service_account_file(
  'SERVICE_ACCOUNT_CREDENTIAL_FILE',
  scopes=SCOPES).with_subject(USER
)
다음을 바꿉니다.
클라이언트 인스턴스화
다음 예시에서는 서비스 계정 사용자 인증 정보를 사용하여 클라이언트를 인스턴스화하는 방법을 보여줍니다.
Python
from google.oauth2 import service_account
import googleapiclient.discovery
SCOPES = ['https://www.googleapis.com/auth/cloud-identity.devices']
def create_service():
  credentials = service_account.Credentials.from_service_account_file(
    'SERVICE_ACCOUNT_CREDENTIAL_FILE',
    scopes=SCOPES
  )
  delegated_credentials = credentials.with_subject('USER')
  service_name = 'cloudidentity'
  api_version = 'v1'
  service = googleapiclient.discovery.build(
    service_name,
    api_version,
    credentials=delegated_credentials)
  return service
다음을 바꿉니다.
이제 기기 API를 호출할 수 있습니다.
대신 최종 사용자로 인증하려면 서비스 계정의 credential 객체를 OAuth 2.0 토큰 가져오기에서 얻을 수 있는 credential로 바꿉니다.
Python 클라이언트 라이브러리 설치
Python 클라이언트 라이브러리를 설치하려면 다음 명령어를 실행합니다.
  pip install --upgrade google-api-python-client google-auth \
    google-auth-oauthlib google-auth-httplib2
Python 개발 환경 설정에 관한 자세한 내용은 Python 개발 환경 설정 가이드를 참조하세요.