インバウンド SAML SSO API を設定する
このページでは、SAML プロファイルを管理したり、シングル サインオン(SSO)の割り当てを構成したりする前に、Cloud Identity Inbound SAML SSO Profiles(inboundSamlSsoProfiles)API と Inbound SSO Assignments(inboundSsoAssignments)API を設定する方法について説明します。
始める前に
インバウンド SAML SSO API を使用する前に、ドメインに Cloud Identity または Google Workspace を設定する必要があります。手順については、Cloud Identity の設定をご覧ください。
Python クライアント ライブラリのインストール
Python クライアント ライブラリと Google 認証ライブラリをインストールするには、次のコマンドを実行します。
pip install --upgrade google-api-python-client google-auth \
google-auth-oauthlib google-auth-httplib2
Python 開発環境の設定の詳細については、Python 開発環境設定ガイドをご覧ください。
API を有効にして認証情報を設定する
- Google Cloud アカウントにログインします。 Google Cloudを初めて使用する場合は、アカウントを作成して、実際のシナリオで Google プロダクトのパフォーマンスを評価してください。新規のお客様には、ワークロードの実行、テスト、デプロイができる無料クレジット $300 分を差し上げます。
-
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 role
(
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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). 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 role
(
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, if it is not already enabled.
Roles required to enable APIs
To enable APIs, you need the
serviceusage.services.enablepermission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.
インバウンド SAML SSO API で認証する
Inbound SAML SSO Profiles API と Inbound SSO Assignments API は、ドメインレベルの認証設定を管理します。呼び出しの認証には、次のいずれかの方法を使用できます。
- ドメイン全体の委任を使用するサービス アカウント(自動ワークフローとバックエンド サービスに推奨): サービス アカウントが Google Workspace または Cloud Identity の特権管理者になりすまして API を呼び出します。
- 管理者 OAuth 2.0 認証情報(インタラクティブ ツールと CLI スクリプトに推奨): 管理者ユーザーが OAuth 2.0 ウェブフローまたはローカル同意フローを介して直接認証します。
OAuth スコープ
Inbound SAML SSO Profiles API と Inbound SSO Assignments API は、次の OAuth スコープをサポートしています。
| 範囲 | 説明 |
|---|---|
https://www.googleapis.com/auth/cloud-identity.inboundsso |
受信 SSO プロファイルと割り当ての作成、更新、削除、取得、一覧表示を行うための完全な読み取り / 書き込みアクセス権。 |
https://www.googleapis.com/auth/cloud-identity.inboundsso.readonly |
インバウンド SSO プロファイルと割り当てを取得して一覧表示するための読み取り専用アクセス権。 |
https://www.googleapis.com/auth/cloud-identity |
すべての Cloud Identity API リソースに対する完全アクセス権。 |
https://www.googleapis.com/auth/cloud-platform |
すべての Google Cloud リソースと API に対する完全アクセス権。 |
ドメイン全体の委任をもつサービス アカウントとして認証する
サービス アカウントから Inbound SAML SSO API を呼び出すには、Google 管理コンソールでサービス アカウントにドメイン全体の委任を付与する必要があります。ドメイン全体の委任により、サービス アカウントは管理者ユーザーになりすますことができるため、サービス アカウントのアクションは、なりすまされた管理者によって実行されたものとして監査ログに表示されます。
ステップ 1: ドメイン全体の権限をサービス アカウントに委任する
- Google Cloud コンソールの [サービス アカウント] ページで、サービス アカウントの OAuth 2 クライアント ID(クライアント ID の数値文字列)をコピーします。
- Google 管理コンソールを開きます。
- [メインメニュー] > [セキュリティ] > [アクセスとデータ管理] > [API の制御] に移動します。
- [ドメイン全体の委任] ペインで、[ドメイン全体の委任を管理] をクリックします。
- [新しく追加] をクリックします。
- [クライアント ID] フィールドに、サービス アカウントのクライアント ID を入力します。
- [OAuth スコープ] フィールドに、必要なスコープをカンマ区切りのリストとして入力します。
- 読み取り / 書き込みアクセス権の場合:
https://www.googleapis.com/auth/cloud-identity.inboundsso - 読み取り専用権限の場合:
https://www.googleapis.com/auth/cloud-identity.inboundsso.readonly
- 読み取り / 書き込みアクセス権の場合:
- [承認] をクリックします。
詳しい手順については、API アクセスをドメイン全体の委任で制御するをご覧ください。
ステップ 2: アプリケーション コードで認証情報を初期化する
アプリケーションで委任された認証情報を初期化するときに、subject パラメータを使用してドメイン管理者のメールアドレスを指定します。
Python
from google.auth import iam
from google.auth.transport import requests
import google.auth
from google.oauth2 import service_account
from googleapiclient.discovery import build
# OAuth scope authorized for domain-wide delegation in the Admin console
SCOPES = ['https://www.googleapis.com/auth/cloud-identity.inboundsso']
# Administrator email address to impersonate
ADMIN_EMAIL = 'admin@example.com'
# Option A: Using a service account JSON key file
# credentials = service_account.Credentials.from_service_account_file(
# 'SERVICE_ACCOUNT_KEY_FILE.json',
# scopes=SCOPES,
# subject=ADMIN_EMAIL
# )
# Option B: Using Application Default Credentials (ADC) with IAM Signer
base_credentials, _ = google.auth.default(
scopes=['https://www.googleapis.com/auth/iam']
)
request = requests.Request()
base_credentials.refresh(request)
signer = iam.Signer(
request,
base_credentials,
base_credentials.service_account_email
)
delegated_credentials = service_account.Credentials(
signer=signer,
service_account_email=base_credentials.service_account_email,
token_uri='https://accounts.google.com/o/oauth2/token',
scopes=SCOPES,
subject=ADMIN_EMAIL
)
# Build the Cloud Identity API client
service = build('cloudidentity', 'v1', credentials=delegated_credentials)
ステップ 3: サービス アカウントの権限借用で gcloud CLI を使用する
アプリケーションのデフォルト認証情報(ADC)とサービス アカウントの権限借用を使用して gcloud CLI で Inbound SAML SSO API をテストまたは呼び出すには、次のコマンドを実行します。
gcloud auth application-default login \
--impersonate-service-account=SERVICE_ACCOUNT_EMAIL \
--scopes=https://www.googleapis.com/auth/iam,https://www.googleapis.com/auth/cloud-identity.inboundsso
次のように置き換えます。
SERVICE_ACCOUNT_EMAIL: ドメイン全体の委任が構成されているサービス アカウントのメールアドレス。
OAuth 2.0 で管理者として認証する
サービス アカウントを使用せずに、インタラクティブなアプリケーションまたはスクリプトを特権管理者として直接認証するには、標準の OAuth 2.0 ユーザー認証情報を使用します。
ウェブ アプリケーションまたはデスクトップ アプリケーションの OAuth 2.0 認証情報を取得する方法については、OAuth 2.0 を使用して Google API にアクセスするをご覧ください。
次のステップ
- インバウンド SAML SSO プロファイルの REST API リファレンスをご覧ください。
- 受信 SSO 割り当て REST API リファレンスをご覧ください。