기기 API 설정

이 페이지에서는 Cloud ID 기기 API를 설정하는 방법을 설명합니다.

API 사용 설정 및 사용자 인증 정보 설정

  1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Google Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다.

  4. Cloud Identity API 사용 설정

    API 사용 설정

  5. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    4. Click Create and continue.
    5. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  6. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.
  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  8. Google Cloud 프로젝트에 결제가 사용 설정되어 있는지 확인합니다.

  9. Cloud Identity API 사용 설정

    API 사용 설정

  10. Create a service account:

    1. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    2. Select your project.
    3. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart.

    4. Click Create and continue.
    5. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner.

    6. Click Continue.
    7. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  11. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys.
    3. Click Add key, and then click Create new key.
    4. Click Create. A JSON key file is downloaded to your computer.
    5. Click Close.

도메인 전체 위임을 사용하여 서비스 계정으로 인증

ID 그룹을 관리하는 관리자이거나 관리자를 대신하여 Google 그룹스를 관리할 수 있는 도메인 전체 권한을 계정에 제공하려면 서비스 계정으로 인증한 다음 서비스 계정에 도메인 전체 권한을 부여해야 합니다.

도메인 전체 위임 설정에 대한 자세한 내용은 도메인 전체 위임으로 API 액세스 제어를 참조하세요.

서비스 계정으로 인증하려면 서버 애플리케이션에 서버용 OAuth 2.0 사용을 참조하세요. 코드에서 사용자 인증 정보를 초기화할 때 사용자 인증 정보의 with_subject()를 호출하여 서비스 계정이 작동할 이메일 주소를 지정합니다. 예를 들면 다음과 같습니다.

Python

credentials = service_account.Credentials.from_service_account_file(
  SERVICE_ACCOUNT_FILE, scopes=SCOPES).with_subject(delegated_email)

클라이언트 인스턴스화

다음 예시에서는 서비스 계정 사용자 인증 정보를 사용하여 클라이언트를 인스턴스화하는 방법을 보여줍니다. 대신 최종 사용자로 인증하려면 credential 객체는 서비스 계정의 웹 서버 애플리케이션용 OAuth 2.0 사용에서 획득한 credential 획득을 교체합니다.

Python

from google.oauth2 import service_account
import googleapiclient.discovery

SCOPES = ['https://www.googleapis.com/auth/cloud-identity.devices']
SERVICE_ACCOUNT_FILE = '/path/to/service-account-file.json'

def create_service():
  credentials = service_account.Credentials.from_service_account_file(
    SERVICE_ACCOUNT_FILE, scopes=SCOPES)
  delegated_credentials = credentials.with_subject('user@example.org')

  service_name = 'cloudidentity'
  api_version = 'v1'
  service = googleapiclient.discovery.build(
    service_name,
    api_version,
    credentials=credentials)

  return service

이제 기기 API를 호출할 수 있습니다.

Python 클라이언트 라이브러리 설치

Python 클라이언트 라이브러리를 설치하려면 다음 명령어를 실행합니다.

  pip install --upgrade google-api-python-client google-auth \
    google-auth-oauthlib google-auth-httplib2

Python 개발 환경 설정에 관한 자세한 내용은 Python 개발 환경 설정 가이드를 참조하세요.