Set up the Inbound SAML SSO APIs
This page explains how to set up the Cloud Identity Inbound SAML SSO Profiles (inboundSamlSsoProfiles) and Inbound SSO Assignments (inboundSsoAssignments) APIs before managing SAML profiles or configuring single sign-on (SSO) assignments.
Before you begin
Before you use the Inbound SAML SSO APIs, you must set up Cloud Identity or Google Workspace for your domain. For instructions, see Setting up Cloud Identity.
Install the Python client library
To install the Python client library and Google authentication libraries, run the following command:
pip install --upgrade google-api-python-client google-auth \
google-auth-oauthlib google-auth-httplib2
For more information about setting up your Python development environment, see the Python Development Environment Setup Guide.
Enable the API and set up credentials
- 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 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.
Authenticate with the Inbound SAML SSO APIs
The Inbound SAML SSO Profiles and Inbound SSO Assignments APIs manage domain-level authentication settings. You can authenticate calls using either of the following methods:
- Service account with domain-wide delegation (recommended for automated workflows and backend services): A service account impersonates a Google Workspace or Cloud Identity super administrator to call the API.
- Administrator OAuth 2.0 credentials (recommended for interactive tools and CLI scripts): An administrator user authenticates directly through an OAuth 2.0 web flow or local consent flow.
OAuth scopes
The Inbound SAML SSO Profiles and Inbound SSO Assignments APIs support the following OAuth scopes:
| Scope | Description |
|---|---|
https://www.googleapis.com/auth/cloud-identity.inboundsso |
Full read and write access to create, update, delete, get, and list inbound SSO profiles and assignments. |
https://www.googleapis.com/auth/cloud-identity.inboundsso.readonly |
Read-only access to get and list inbound SSO profiles and assignments. |
https://www.googleapis.com/auth/cloud-identity |
Full access to all Cloud Identity API resources. |
https://www.googleapis.com/auth/cloud-platform |
Full access to all Google Cloud resources and APIs. |
Authenticate as a service account with domain-wide delegation
To call the Inbound SAML SSO APIs from a service account, you must grant the service account domain-wide delegation in the Google Admin console. Because domain-wide delegation lets the service account impersonate an administrator user, service account actions appear in the audit logs as having been performed by the impersonated administrator.
Step 1: Delegate domain-wide authority to the service account
- In the Google Cloud console, copy the OAuth 2 Client ID (client ID numeric string) of your service account from the Service Accounts page.
- Open the Google Admin console.
- Go to Main menu > Security > Access and data control > API controls.
- In the Domain wide delegation pane, click Manage Domain Wide Delegation.
- Click Add new.
- In the Client ID field, enter the client ID of the service account.
- In the OAuth scopes field, enter the required scopes as a comma-separated list:
- For read and write access:
https://www.googleapis.com/auth/cloud-identity.inboundsso - For read-only access:
https://www.googleapis.com/auth/cloud-identity.inboundsso.readonly
- For read and write access:
- Click Authorize.
For detailed instructions, see Control API access with domain-wide delegation.
Step 2: Initialize credentials in application code
When you initialize delegated credentials in your application, specify the email address of the domain administrator by using the subject parameter:
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)
Step 3: Use the gcloud CLI with service account impersonation
To test or call the Inbound SAML SSO APIs by using the gcloud CLI with Application Default Credentials (ADC) and service account impersonation, run the following command:
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
Replace the following:
SERVICE_ACCOUNT_EMAIL: the email address of the service account that has domain-wide delegation configured.
Authenticate as an administrator with OAuth 2.0
To authenticate an interactive application or script directly as a super administrator without a service account, use standard OAuth 2.0 user credentials.
For more information about obtaining OAuth 2.0 credentials for web or desktop applications, see Using OAuth 2.0 to access Google APIs.
What's next
- Refer to the Inbound SAML SSO Profiles REST API reference.
- Refer to the Inbound SSO Assignments REST API reference.