diff --git a/i18n/de/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/de/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index c198530684a..a0a685b702d 100644 --- a/i18n/de/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/de/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,6 +3,7 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; @@ -51,7 +52,7 @@ Wenn du Fragen zu Cloud-Diensten hast und zusätzliche Unterstützung benötigst label: 'Eigene Domains', href: '/logto-cloud/custom-domain', description: - 'Verwende deine eigene Domain für deinen Logto-Mandanten, um ein konsistentes Branding in deiner Endbenutzererfahrung zu gewährleisten.', + 'Nutze deine eigene Domain für deinen Logto-Mandanten, um ein konsistentes Branding für deine Endnutzererfahrung zu gewährleisten.', customProps: { icon: , }, @@ -75,6 +76,16 @@ Wenn du Fragen zu Cloud-Diensten hast und zusätzliche Unterstützung benötigst icon: , }, }, + { + type: 'link', + label: 'Mandantenverwaltung automatisieren', + href: '/logto-cloud/automate-tenant-creation', + description: + 'Erstelle und verwalte Mandanten programmatisch mit Logto Cloud API und Management API.', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP Server', diff --git a/i18n/de/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/de/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..010fbe18a0d --- /dev/null +++ b/i18n/de/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: Mandantenverwaltung automatisieren +sidebar_position: 8 +--- + +# Mandantenverwaltung automatisieren + +Du kannst Logto Cloud Mandanten programmatisch verwalten, einschließlich der Erstellung von Mandanten und der weiteren Konfiguration, ohne zur Konsole wechseln zu müssen. + +Dies ist nützlich, wenn du Mandanten aus deinem eigenen Onboarding-Flow, einer internen Plattform, einem KI-Agenten oder einer Integrationsautomatisierung bereitstellen musst. + +Der Automatisierungsablauf ist: + +1. Verwende ein **Logto Cloud Personal Access Token (PAT)**, um die Logto Cloud API aufzurufen. +2. Erstelle einen Mandanten mit `POST /api/tenants`. +3. Lies die Standard-Maschine-zu-Maschine (M2M) Anwendungs-Zugangsdaten aus der Antwort zur Erstellung aus. +4. Verwende die Standard-M2M-Anwendung, um ein Management API Zugangstoken für den neuen Mandanten zu erhalten. +5. Rufe die Management API des neuen Mandanten auf, um die Bereitstellung von Anwendungen, Benutzern, Rollen, Ressourcen, Organisationen und anderen Einstellungen fortzusetzen. + +## Bevor du beginnst \{#before-you-start} + +Bereite die folgenden Werte vor: + +| Variable | Beschreibung | +| -------------------- | -------------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | Der Logto Cloud API-Endpunkt. Für Logto Cloud verwende `https://cloud.logto.io`. | +| `LOGTO_CLOUD_PAT` | Ein PAT für dein Logto Cloud Konto. | +| `TENANT_NAME` | Der Anzeigename des zu erstellenden Mandanten. | +| `TENANT_TAG` | Der Mandantentyp. Verwende `development` oder `production`. | +| `REGION_NAME` | Die Regionskennung für den Mandanten. | + +Setze sie als Umgebungsvariablen: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="Mein automatisierter Mandant" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## Verfügbare Regionen abrufen \{#get-available-regions} + +Bevor du einen Mandanten erstellst, rufe die für dein Logto Cloud Konto verfügbaren Regionen ab: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +Die Antwort enthält die verfügbaren Regionen. Verwende den Wert von `name` als `REGION_NAME`, wenn du den Mandanten erstellst. + +Beispielantwort: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## Einen Mandanten erstellen \{#create-a-tenant} + +Rufe `POST /api/tenants` mit dem Logto Cloud PAT auf: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +Die Antwort enthält den erstellten Mandanten und eine Standard-M2M-Anwendung. Die M2M-Anwendung wird im neuen Mandanten erstellt und hat Zugriff auf die Management API des Mandanten. + +Beispielantwort: + +```json +{ + "id": "new-tenant-id", + "name": "Mein automatisierter Mandant", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +Speichere die Werte, die du für den nächsten Schritt benötigst: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## Ein Management API Zugangstoken für den neuen Mandanten erhalten \{#get-a-management-api-access-token-for-the-new-tenant} + +Verwende die Zugangsdaten der Standard-M2M-Anwendung, um ein Zugangstoken vom neuen Mandanten anzufordern: + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +Beispielantwort: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +Speichere das Zugangstoken: + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## Die Bereitstellung des neuen Mandanten fortsetzen \{#continue-provisioning-the-new-tenant} + +Verwende das Management API Zugangstoken, um die Management API des neuen Mandanten aufzurufen. + +Zum Beispiel, um Anwendungen aufzulisten: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +Oder um eine Anwendung zu erstellen: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "Meine Web-App", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +An diesem Punkt kann deine Automatisierung mit jeder Management API-Operation fortfahren, wie z. B. dem Erstellen von Benutzern, Anwendungen, API-Ressourcen, Rollen, Organisationen, Connectors oder Einstellungen für die Anmeldeerfahrung. + +## Vollständiges Automatisierungsbeispiel \{#full-automation-example} + +Das folgende Node.js-Beispiel erstellt einen Mandanten, tauscht die zurückgegebenen Standard-M2M-Zugangsdaten gegen ein Management API Zugangstoken aus und listet Anwendungen im neuen Mandanten auf: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'Mein automatisierter Mandant', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`Fehler beim Erstellen des Mandanten: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Fehler beim Abrufen des Management API Tokens: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`Fehler beim Auflisten der Anwendungen: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## Verwandte Ressourcen \{#related-resources} + +- [Personal Access Token](/user-management/personal-access-token) +- [Mit Management API interagieren](/integrate-logto/interact-with-management-api) +- [Maschine-zu-Maschine Schnellstart](/quick-starts/m2m) diff --git a/i18n/es/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/es/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index 7b743b7a9b6..1e365a00e34 100644 --- a/i18n/es/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/es/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,6 +3,7 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; @@ -31,7 +32,7 @@ Si tienes alguna pregunta sobre los servicios en la nube y necesitas soporte adi label: 'Política de retención de datos del tenant de desarrollo', href: '/logto-cloud/dev-tenant-data-retention', description: - 'Comprende la política de retención de usuarios por 90 días en el tenant de desarrollo y cómo usar Logto dev tenant de manera efectiva.', + 'Entiende la política de retención de usuarios por 90 días para tenants de desarrollo y cómo usar Logto dev tenant de manera efectiva.', customProps: { icon: , }, @@ -51,7 +52,7 @@ Si tienes alguna pregunta sobre los servicios en la nube y necesitas soporte adi label: 'Dominios personalizados', href: '/logto-cloud/custom-domain', description: - 'Utiliza tu propio dominio para tu tenant de Logto y mantén la coherencia de marca en la experiencia de usuario final.', + 'Utiliza tu propio dominio para tu tenant de Logto y mantén la coherencia de marca en la experiencia del usuario final.', customProps: { icon: , }, @@ -60,7 +61,7 @@ Si tienes alguna pregunta sobre los servicios en la nube y necesitas soporte adi type: 'link', label: 'Facturación y precios', href: '/logto-cloud/billing-and-pricing', - description: 'Comprende fácilmente tu factura y gestiona tu suscripción con confianza.', + description: 'Entiende fácilmente tu factura y gestiona tu suscripción con confianza.', customProps: { icon: , }, @@ -70,17 +71,27 @@ Si tienes alguna pregunta sobre los servicios en la nube y necesitas soporte adi label: 'Límite del sistema', href: '/logto-cloud/system-limit', description: - 'Comprende los límites del sistema y la protección de tasas para tenants Dev, Pro y Enterprise.', + 'Comprende los límites del sistema y la protección de tasa para tenants Dev, Pro y Enterprise.', customProps: { icon: , }, }, + { + type: 'link', + label: 'Automatiza la gestión del tenant', + href: '/logto-cloud/automate-tenant-creation', + description: + 'Crea y gestiona tenants programáticamente con Logto Cloud API y Management API.', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP Server', href: '/logto-cloud/logto-mcp-server', description: - 'Conecta herramientas de IA e IDEs a Logto Cloud mediante MCP para gestionar recursos e integrar autenticación.', + 'Conecta herramientas de IA e IDEs a Logto Cloud vía MCP para gestionar recursos e integrar autenticación.', customProps: { icon: , }, diff --git a/i18n/es/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/es/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..a3adee00fda --- /dev/null +++ b/i18n/es/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: Automatiza la gestión de tenants +sidebar_position: 8 +--- + +# Automatiza la gestión de tenants + +Puedes gestionar los tenants de Logto Cloud de forma programática, incluyendo la creación de tenants y la continuación de la configuración sin cambiar a la Consola. + +Esto es útil cuando necesitas aprovisionar tenants desde tu propio flujo de onboarding, plataforma interna, agente de IA o automatización de integraciones. + +El flujo de automatización es: + +1. Usa un **Logto Cloud Personal Access Token (PAT)** para llamar a la API de Logto Cloud. +2. Crea un tenant con `POST /api/tenants`. +3. Lee las credenciales predeterminadas de la aplicación máquina a máquina (M2M) de la respuesta de creación. +4. Usa la aplicación M2M predeterminada para obtener un token de acceso de la Management API para el nuevo tenant. +5. Llama a la Management API del nuevo tenant para continuar aprovisionando aplicaciones, usuarios, roles, recursos, organizaciones y otros ajustes. + +## Antes de comenzar \{#before-you-start} + +Prepara los siguientes valores: + +| Variable | Descripción | +| -------------------- | ------------------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | El endpoint de la API de Logto Cloud. Para Logto Cloud, usa `https://cloud.logto.io`. | +| `LOGTO_CLOUD_PAT` | Un PAT para tu cuenta de Logto Cloud. | +| `TENANT_NAME` | El nombre visible del tenant a crear. | +| `TENANT_TAG` | El tipo de tenant. Usa `development` o `production`. | +| `REGION_NAME` | El identificador de la región para el tenant. | + +Establécelos como variables de entorno: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="Mi tenant automatizado" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## Obtener regiones disponibles \{#get-available-regions} + +Antes de crear un tenant, obtén las regiones disponibles para tu cuenta de Logto Cloud: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +La respuesta contiene las regiones disponibles. Usa el valor `name` como `REGION_NAME` al crear el tenant. + +Ejemplo de respuesta: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## Crear un tenant \{#create-a-tenant} + +Llama a `POST /api/tenants` con el Logto Cloud PAT: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +La respuesta incluye el tenant creado y una aplicación M2M predeterminada. La aplicación M2M se crea en el nuevo tenant y tiene acceso a la Management API del tenant. + +Ejemplo de respuesta: + +```json +{ + "id": "new-tenant-id", + "name": "Mi tenant automatizado", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +Guarda los valores que necesitas para el siguiente paso: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## Obtener un token de acceso de la Management API para el nuevo tenant \{#get-a-management-api-access-token-for-the-new-tenant} + +Usa las credenciales de la aplicación M2M predeterminada para solicitar un token de acceso del nuevo tenant: + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +Ejemplo de respuesta: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +Guarda el token de acceso: + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## Continuar aprovisionando el nuevo tenant \{#continue-provisioning-the-new-tenant} + +Usa el token de acceso de la Management API para llamar a la Management API del nuevo tenant. + +Por ejemplo, listar aplicaciones: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +O crear una aplicación: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "Mi aplicación web", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +En este punto, tu automatización puede continuar con cualquier operación de la Management API, como crear usuarios, aplicaciones, recursos de API, roles, organizaciones, conectores o ajustes de experiencia de inicio de sesión. + +## Ejemplo de automatización completa \{#full-automation-example} + +El siguiente ejemplo en Node.js crea un tenant, intercambia las credenciales M2M predeterminadas devueltas por un token de acceso de la Management API y lista las aplicaciones en el nuevo tenant: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'Mi tenant automatizado', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`Error al crear el tenant: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Error al obtener el token de la Management API: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`Error al listar aplicaciones: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## Recursos relacionados \{#related-resources} + +- [Personal access token](/user-management/personal-access-token) +- [Interactuar con la Management API](/integrate-logto/interact-with-management-api) +- [Inicio rápido máquina a máquina](/quick-starts/m2m) diff --git a/i18n/fr/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/fr/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index bafed92d808..44b836fa119 100644 --- a/i18n/fr/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/fr/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,14 +3,15 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; # Logto Cloud -[Logto Cloud](https://cloud.logto.io) propose une gamme de services de gestion et d'exploitation pour vous aider à gérer les identités et les ressources de manière fluide et simple. Hébergé par Logto, il inclut des fonctionnalités telles que [prise en charge multi-régions](/logto-cloud/tenant-settings#tenant-region), gestion des locataires, [facturation et tarification](/logto-cloud/billing-and-pricing), [gestion des membres](/logto-cloud/tenant-member-management) et contrôle d’accès basé sur les rôles dans la console. +[Logto Cloud](https://cloud.logto.io) propose une gamme de services de gestion et d'exploitation pour vous aider à gérer les identités et les ressources de manière fluide et simple. Hébergé par Logto, il inclut des fonctionnalités telles que [prise en charge multi-régions](/logto-cloud/tenant-settings#tenant-region), gestion des tenants, [facturation et tarification](/logto-cloud/billing-and-pricing), [gestion des membres](/logto-cloud/tenant-member-management) et contrôle d’accès basé sur les rôles dans la console. -Si vous avez des questions concernant les services cloud et avez besoin d’un support supplémentaire, veuillez nous contacter. +Si vous avez des questions concernant les services cloud ou si vous avez besoin d’un support supplémentaire, veuillez nous contacter. ## Fonctionnalités du service cloud \{#features-for-cloud-service} @@ -18,30 +19,30 @@ Si vous avez des questions concernant les services cloud et avez besoin d’un s items={[ { type: 'link', - label: 'Paramètres du locataire', + label: 'Paramètres du tenant', href: '/logto-cloud/tenant-settings', description: - 'Mettez à jour ou modifiez le nom du locataire, vérifiez les régions et supprimez ou quittez le locataire.', + 'Mettez à jour ou modifiez le nom du tenant, vérifiez les régions, et supprimez ou quittez le tenant.', customProps: { icon: , }, }, { type: 'link', - label: 'Politique de conservation des données du locataire de développement', + label: 'Politique de conservation des données du tenant de développement', href: '/logto-cloud/dev-tenant-data-retention', description: - 'Comprenez la politique de conservation des utilisateurs sur 90 jours pour les locataires de développement et comment utiliser efficacement un locataire de développement Logto.', + 'Comprenez la politique de conservation des utilisateurs sur 90 jours pour le tenant de développement et comment utiliser efficacement le tenant de développement Logto.', customProps: { icon: , }, }, { type: 'link', - label: 'Gestion des membres du locataire', + label: 'Gestion des membres du tenant', href: '/logto-cloud/tenant-member-management', description: - 'L’administrateur du locataire peut inviter et gérer les membres et mettre à jour leurs rôles.', + 'L’administrateur du tenant peut inviter et gérer les membres et mettre à jour leurs rôles.', customProps: { icon: , }, @@ -51,7 +52,7 @@ Si vous avez des questions concernant les services cloud et avez besoin d’un s label: 'Domaines personnalisés', href: '/logto-cloud/custom-domain', description: - 'Utilisez votre propre domaine pour votre locataire Logto afin de garantir la cohérence de la marque dans l’expérience utilisateur finale.', + 'Utilisez votre propre domaine pour votre tenant Logto afin de garder la cohérence de la marque dans l’expérience utilisateur.', customProps: { icon: , }, @@ -71,11 +72,21 @@ Si vous avez des questions concernant les services cloud et avez besoin d’un s label: 'Limite du système', href: '/logto-cloud/system-limit', description: - 'Comprenez les limites du système et la protection contre les dépassements pour les locataires Dev, Pro et Enterprise.', + 'Comprenez les limites du système et la protection contre les dépassements pour les tenants Dev, Pro et Enterprise.', customProps: { icon: , }, }, + { + type: 'link', + label: 'Automatiser la gestion des tenants', + href: '/logto-cloud/automate-tenant-creation', + description: + 'Créez et gérez des tenants de manière programmatique avec Logto Cloud API et Management API.', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP Server', diff --git a/i18n/fr/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/fr/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..607c430a7bb --- /dev/null +++ b/i18n/fr/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: Automatiser la gestion des locataires +sidebar_position: 8 +--- + +# Automatiser la gestion des locataires + +Vous pouvez gérer les locataires Logto Cloud de manière programmatique, y compris créer des locataires et poursuivre la configuration sans passer par la Console. + +Ceci est utile lorsque vous devez approvisionner des locataires depuis votre propre parcours d'intégration, une plateforme interne, un agent IA ou une automatisation d'intégration. + +Le flux d'automatisation est le suivant : + +1. Utilisez un **Logto Cloud Personal Access Token (PAT)** pour appeler l'API Logto Cloud. +2. Créez un locataire avec `POST /api/tenants`. +3. Lisez les identifiants de l'application machine à machine (M2M) par défaut dans la réponse de création. +4. Utilisez l'application M2M par défaut pour obtenir un jeton d’accès Management API pour le nouveau locataire. +5. Appelez la Management API du nouveau locataire pour continuer l'approvisionnement des applications, utilisateurs, rôles, ressources, organisations et autres paramètres. + +## Avant de commencer \{#before-you-start} + +Préparez les valeurs suivantes : + +| Variable | Description | +| -------------------- | -------------------------------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | Le point de terminaison de l'API Logto Cloud. Pour Logto Cloud, utilisez `https://cloud.logto.io`. | +| `LOGTO_CLOUD_PAT` | Un PAT pour votre compte Logto Cloud. | +| `TENANT_NAME` | Le nom d'affichage du locataire à créer. | +| `TENANT_TAG` | Le type de locataire. Utilisez `development` ou `production`. | +| `REGION_NAME` | L'identifiant de la région pour le locataire. | + +Définissez-les comme variables d'environnement : + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="Mon locataire automatisé" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## Obtenir les régions disponibles \{#get-available-regions} + +Avant de créer un locataire, récupérez les régions disponibles pour votre compte Logto Cloud : + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +La réponse contient les régions disponibles. Utilisez la valeur `name` comme `REGION_NAME` lors de la création du locataire. + +Exemple de réponse : + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## Créer un locataire \{#create-a-tenant} + +Appelez `POST /api/tenants` avec le PAT Logto Cloud : + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +La réponse inclut le locataire créé et une application M2M par défaut. L'application M2M est créée dans le nouveau locataire et a accès à la Management API du locataire. + +Exemple de réponse : + +```json +{ + "id": "new-tenant-id", + "name": "Mon locataire automatisé", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +Enregistrez les valeurs nécessaires pour l'étape suivante : + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## Obtenir un jeton d’accès Management API pour le nouveau locataire \{#get-a-management-api-access-token-for-the-new-tenant} + +Utilisez les identifiants de l'application M2M par défaut pour demander un jeton d’accès au nouveau locataire : + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +Exemple de réponse : + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +Enregistrez le jeton d’accès : + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## Continuer l'approvisionnement du nouveau locataire \{#continue-provisioning-the-new-tenant} + +Utilisez le jeton d’accès Management API pour appeler la Management API du nouveau locataire. + +Par exemple, lister les applications : + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +Ou créer une application : + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "Mon application web", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +À ce stade, votre automatisation peut continuer avec toute opération Management API, comme la création d'utilisateurs, d'applications, de ressources API, de rôles, d'organisations, de connecteurs ou de paramètres d'expérience de connexion. + +## Exemple d'automatisation complète \{#full-automation-example} + +L'exemple Node.js suivant crée un locataire, échange les identifiants M2M par défaut retournés contre un jeton d’accès Management API, et liste les applications du nouveau locataire : + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'Mon locataire automatisé', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`Échec de la création du locataire : ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Échec de l'obtention du jeton Management API : ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`Échec de la liste des applications : ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## Ressources associées \{#related-resources} + +- [Jeton d’accès personnel](/user-management/personal-access-token) +- [Interagir avec Management API](/integrate-logto/interact-with-management-api) +- [Démarrage rapide machine à machine](/quick-starts/m2m) diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/ja/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index 13a60e51769..a2adeb841b1 100644 --- a/i18n/ja/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/ja/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,14 +3,15 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; # Logto Cloud -[Logto Cloud](https://cloud.logto.io) は、アイデンティティやリソースをスムーズかつ簡単に管理できるように、さまざまな管理・運用サービスを提供しています。Logto によってホストされており、[マルチリージョンサポート](/logto-cloud/tenant-settings#tenant-region)、テナント管理、[請求と料金](/logto-cloud/billing-and-pricing)、[メンバー管理](/logto-cloud/tenant-member-management)、およびコンソールのロールベースのアクセス制御などの機能が含まれています。 +[Logto Cloud](https://cloud.logto.io) は、アイデンティティやリソースをスムーズかつ簡単に管理できるように、さまざまな管理・運用サービスを提供しています。Logto によってホストされており、[マルチリージョンサポート](/logto-cloud/tenant-settings#tenant-region)、テナント管理、[請求と価格設定](/logto-cloud/billing-and-pricing)、[メンバー管理](/logto-cloud/tenant-member-management)、およびコンソールのロールベースのアクセス制御などの機能が含まれています。 -クラウドサービスに関するご質問や追加サポートが必要な場合は、お問い合わせください。 +クラウドサービスに関するご質問や追加サポートが必要な場合は、お気軽にお問い合わせください。 ## クラウドサービスの機能 \{#features-for-cloud-service} @@ -39,7 +40,7 @@ import SystemLimit from '@site/src/assets/security.svg'; type: 'link', label: 'テナントメンバー管理', href: '/logto-cloud/tenant-member-management', - description: 'テナント管理者はメンバーの招待・管理やロールの更新ができます。', + description: 'テナント管理者はメンバーの招待・管理やロールの更新が可能です。', customProps: { icon: , }, @@ -56,9 +57,9 @@ import SystemLimit from '@site/src/assets/security.svg'; }, { type: 'link', - label: '請求と料金', + label: '請求と価格設定', href: '/logto-cloud/billing-and-pricing', - description: '請求内容を簡単に把握し、自信を持ってサブスクリプションを管理できます。', + description: '請求内容を簡単に把握し、安心してサブスクリプションを管理できます。', customProps: { icon: , }, @@ -72,12 +73,22 @@ import SystemLimit from '@site/src/assets/security.svg'; icon: , }, }, + { + type: 'link', + label: 'テナント管理の自動化', + href: '/logto-cloud/automate-tenant-creation', + description: + 'Logto Cloud API および Management API を使って、テナントをプログラムで作成・管理できます。', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP サーバー', href: '/logto-cloud/logto-mcp-server', description: - 'AI ツールや IDE を MCP 経由で Logto Cloud に接続し、リソース管理や認証 (Authentication) 連携を実現します。', + 'AI ツールや IDE を MCP 経由で Logto Cloud に接続し、リソース管理や認証 (Authentication) 連携が可能です。', customProps: { icon: , }, diff --git a/i18n/ja/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/ja/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..1ebc54a20b5 --- /dev/null +++ b/i18n/ja/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: テナント管理の自動化 +sidebar_position: 8 +--- + +# テナント管理の自動化 + +Logto Cloud テナントはプログラムで管理できます。これにはテナントの作成や、Console に切り替えることなく設定を継続することが含まれます。 + +この機能は、独自のオンボーディングフローや社内プラットフォーム、AI エージェント、統合自動化からテナントをプロビジョニングする必要がある場合に便利です。 + +自動化フローは次の通りです: + +1. **Logto Cloud パーソナルアクセストークン (PAT)** を使って Logto Cloud API を呼び出します。 +2. `POST /api/tenants` でテナントを作成します。 +3. 作成レスポンスからデフォルトのマシン間通信 (M2M) アプリケーションの認証情報を取得します。 +4. デフォルトの M2M アプリケーションを使って新しいテナントの Management API アクセストークンを取得します。 +5. 新しいテナントの Management API を呼び出し、アプリケーション、ユーザー、ロール、リソース、組織、その他の設定のプロビジョニングを継続します。 + +## 始める前に \{#before-you-start} + +次の値を準備してください: + +| Variable | Description | +| -------------------- | -------------------------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | Logto Cloud API エンドポイント。Logto Cloud の場合は `https://cloud.logto.io` を使用します。 | +| `LOGTO_CLOUD_PAT` | Logto Cloud アカウント用の PAT。 | +| `TENANT_NAME` | 作成するテナントの表示名。 | +| `TENANT_TAG` | テナントタイプ。`development` または `production` を使用します。 | +| `REGION_NAME` | テナントのリージョン識別子。 | + +これらを環境変数として設定します: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="My automated tenant" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## 利用可能なリージョンの取得 \{#get-available-regions} + +テナントを作成する前に、Logto Cloud アカウントで利用可能なリージョンを取得します: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +レスポンスには利用可能なリージョンが含まれます。テナント作成時には `name` の値を `REGION_NAME` として使用します。 + +レスポンス例: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## テナントの作成 \{#create-a-tenant} + +Logto Cloud PAT を使って `POST /api/tenants` を呼び出します: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +レスポンスには作成されたテナントとデフォルトの M2M アプリケーションが含まれます。M2M アプリケーションは新しいテナント内に作成され、そのテナントの Management API へのアクセス権を持ちます。 + +レスポンス例: + +```json +{ + "id": "new-tenant-id", + "name": "My automated tenant", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +次のステップで必要な値を保存します: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## 新しいテナントの Management API アクセストークンの取得 \{#get-a-management-api-access-token-for-the-new-tenant} + +デフォルトの M2M アプリケーション認証情報を使って、新しいテナントからアクセストークンをリクエストします: + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +レスポンス例: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +アクセストークンを保存します: + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## 新しいテナントのプロビジョニングを継続 \{#continue-provisioning-the-new-tenant} + +Management API アクセストークンを使って、新しいテナントの Management API を呼び出します。 + +例えば、アプリケーション一覧を取得する場合: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +またはアプリケーションを作成する場合: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "My web app", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +この時点で、ユーザー、アプリケーション、API リソース、ロール、組織、コネクター、サインイン体験設定など、任意の Management API 操作による自動化を継続できます。 + +## フル自動化例 \{#full-automation-example} + +以下の Node.js サンプルは、テナントを作成し、返されたデフォルト M2M 認証情報で Management API アクセストークンを取得し、新しいテナント内のアプリケーション一覧を取得します: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'My automated tenant', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`Failed to create tenant: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Failed to get Management API token: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`Failed to list applications: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## 関連リソース \{#related-resources} + +- [パーソナルアクセストークン](/user-management/personal-access-token) +- [Management API との連携](/integrate-logto/interact-with-management-api) +- [マシン間通信クイックスタート](/quick-starts/m2m) diff --git a/i18n/ko/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/ko/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index afd6b792d0a..192a4d81b6f 100644 --- a/i18n/ko/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/ko/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,12 +3,13 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; # Logto Cloud -[Logto Cloud](https://cloud.logto.io) 는 아이덴티티와 리소스를 원활하고 쉽게 관리할 수 있도록 다양한 관리 및 운영 서비스를 제공합니다. Logto에서 호스팅하며, [다중 리전 지원](/logto-cloud/tenant-settings#tenant-region), 테넌트 관리, [청구 및 가격 정책](/logto-cloud/billing-and-pricing), [멤버 관리](/logto-cloud/tenant-member-management), 콘솔 역할 기반 접근 제어 등 다양한 기능을 포함합니다. +[Logto Cloud](https://cloud.logto.io)는 아이덴티티와 리소스를 원활하고 쉽게 관리할 수 있도록 다양한 관리 및 운영 서비스를 제공합니다. Logto에서 호스팅하며, [다중 리전 지원](/logto-cloud/tenant-settings#tenant-region), 테넌트 관리, [청구 및 가격](/logto-cloud/billing-and-pricing), [멤버 관리](/logto-cloud/tenant-member-management), 콘솔 역할 기반 접근 제어 (RBAC) 등의 기능을 포함합니다. 클라우드 서비스에 대해 궁금한 점이 있거나 추가 지원이 필요하시면 언제든지 문의해 주세요. @@ -31,7 +32,7 @@ import SystemLimit from '@site/src/assets/security.svg'; label: '개발 테넌트 데이터 보존 정책', href: '/logto-cloud/dev-tenant-data-retention', description: - '개발 테넌트의 90일 사용자 보존 정책과 Logto 개발 테넌트의 효과적인 사용 방법을 알아보세요.', + '개발 테넌트의 90일 사용자 보존 정책을 이해하고 Logto 개발 테넌트를 효과적으로 사용하는 방법을 알아보세요.', customProps: { icon: , }, @@ -57,9 +58,9 @@ import SystemLimit from '@site/src/assets/security.svg'; }, { type: 'link', - label: '청구 및 가격 정책', + label: '청구 및 가격', href: '/logto-cloud/billing-and-pricing', - description: '청구서를 쉽게 이해하고 구독을 안심하고 관리할 수 있습니다.', + description: '청구서를 쉽게 이해하고 구독을 안심하고 관리하세요.', customProps: { icon: , }, @@ -75,7 +76,17 @@ import SystemLimit from '@site/src/assets/security.svg'; }, { type: 'link', - label: 'Logto MCP Server', + label: '테넌트 관리 자동화', + href: '/logto-cloud/automate-tenant-creation', + description: + 'Logto Cloud API 및 Management API를 사용하여 테넌트를 프로그래밍 방식으로 생성 및 관리하세요.', + customProps: { + icon: , + }, + }, + { + type: 'link', + label: 'Logto MCP 서버', href: '/logto-cloud/logto-mcp-server', description: 'AI 도구 및 IDE를 MCP를 통해 Logto Cloud에 연결하여 리소스를 관리하고 인증 (Authentication)을 통합하세요.', diff --git a/i18n/ko/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/ko/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..333e8f16e18 --- /dev/null +++ b/i18n/ko/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: 테넌트 관리 자동화 +sidebar_position: 8 +--- + +# 테넌트 관리 자동화 + +Logto Cloud 테넌트는 프로그래밍 방식으로 관리할 수 있습니다. 테넌트 생성 및 추가 설정을 Console로 전환하지 않고도 계속 진행할 수 있습니다. + +이는 자체 온보딩 플로우, 내부 플랫폼, AI 에이전트, 또는 통합 자동화에서 테넌트를 프로비저닝해야 할 때 유용합니다. + +자동화 흐름은 다음과 같습니다: + +1. **Logto Cloud 개인 액세스 토큰 (PAT)**을 사용하여 Logto Cloud API를 호출합니다. +2. `POST /api/tenants`로 테넌트를 생성합니다. +3. 생성 응답에서 기본 기계 간 (M2M) 애플리케이션 자격 증명을 읽어옵니다. +4. 기본 M2M 애플리케이션을 사용하여 새 테넌트의 Management API 액세스 토큰을 얻습니다. +5. 새 테넌트의 Management API를 호출하여 애플리케이션, 사용자, 역할, 리소스, 조직, 기타 설정을 계속 프로비저닝합니다. + +## 시작하기 전에 \{#before-you-start} + +다음 값을 준비하세요: + +| Variable | Description | +| -------------------- | ------------------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | Logto Cloud API 엔드포인트. Logto Cloud의 경우 `https://cloud.logto.io`를 사용하세요. | +| `LOGTO_CLOUD_PAT` | Logto Cloud 계정의 PAT. | +| `TENANT_NAME` | 생성할 테넌트의 표시 이름. | +| `TENANT_TAG` | 테넌트 유형. `development` 또는 `production`을 사용하세요. | +| `REGION_NAME` | 테넌트의 지역 식별자. | + +환경 변수로 설정하세요: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="My automated tenant" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## 사용 가능한 지역 가져오기 \{#get-available-regions} + +테넌트를 생성하기 전에, Logto Cloud 계정에서 사용 가능한 지역을 조회하세요: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +응답에는 사용 가능한 지역이 포함되어 있습니다. 테넌트 생성 시 `REGION_NAME`으로 `name` 값을 사용하세요. + +예시 응답: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## 테넌트 생성하기 \{#create-a-tenant} + +Logto Cloud PAT으로 `POST /api/tenants`를 호출하세요: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +응답에는 생성된 테넌트와 기본 M2M 애플리케이션이 포함됩니다. M2M 애플리케이션은 새 테넌트에 생성되며, 해당 테넌트의 Management API에 접근할 수 있습니다. + +예시 응답: + +```json +{ + "id": "new-tenant-id", + "name": "My automated tenant", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +다음 단계에 필요한 값을 저장하세요: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## 새 테넌트의 Management API 액세스 토큰 받기 \{#get-a-management-api-access-token-for-the-new-tenant} + +기본 M2M 애플리케이션 자격 증명을 사용하여 새 테넌트에서 액세스 토큰을 요청하세요: + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +예시 응답: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +액세스 토큰을 저장하세요: + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## 새 테넌트 프로비저닝 계속하기 \{#continue-provisioning-the-new-tenant} + +Management API 액세스 토큰을 사용하여 새 테넌트의 Management API를 호출하세요. + +예를 들어, 애플리케이션 목록 조회: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +또는 애플리케이션 생성: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "My web app", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +이 시점에서, 자동화는 사용자, 애플리케이션, API 리소스, 역할, 조직, 커넥터, 로그인 경험 설정 등 모든 Management API 작업을 계속할 수 있습니다. + +## 전체 자동화 예시 \{#full-automation-example} + +다음 Node.js 예시는 테넌트를 생성하고, 반환된 기본 M2M 자격 증명으로 Management API 액세스 토큰을 교환한 뒤, 새 테넌트의 애플리케이션 목록을 조회합니다: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'My automated tenant', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`테넌트 생성 실패: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Management API 토큰 획득 실패: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`애플리케이션 목록 조회 실패: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## 관련 리소스 \{#related-resources} + +- [개인 액세스 토큰](/user-management/personal-access-token) +- [Management API와 상호작용하기](/integrate-logto/interact-with-management-api) +- [기계 간 (M2M) 빠른 시작](/quick-starts/m2m) diff --git a/i18n/pt-BR/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/pt-BR/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index 69d958e43a3..aafc19113c7 100644 --- a/i18n/pt-BR/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/pt-BR/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,6 +3,7 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; @@ -31,7 +32,7 @@ Se você tiver dúvidas sobre os serviços em nuvem e precisar de suporte adicio label: 'Política de retenção de dados do tenant de desenvolvimento', href: '/logto-cloud/dev-tenant-data-retention', description: - 'Entenda a política de retenção de usuários por 90 dias do tenant de desenvolvimento e como usar o tenant de desenvolvimento do Logto de forma eficaz.', + 'Entenda a política de retenção de usuários por 90 dias do tenant de desenvolvimento e como usar o tenant de desenvolvimento Logto de forma eficaz.', customProps: { icon: , }, @@ -75,6 +76,16 @@ Se você tiver dúvidas sobre os serviços em nuvem e precisar de suporte adicio icon: , }, }, + { + type: 'link', + label: 'Automatizar o gerenciamento de tenants', + href: '/logto-cloud/automate-tenant-creation', + description: + 'Crie e gerencie tenants programaticamente com Logto Cloud API e Management API.', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP Server', diff --git a/i18n/pt-BR/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/pt-BR/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..1ec3ec5f69c --- /dev/null +++ b/i18n/pt-BR/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,245 @@ +--- +id: automate-tenant-creation +title: Automatizar o gerenciamento de tenants +sidebar_position: 8 +--- + +# Automatizar o gerenciamento de tenants + +Você pode gerenciar tenants do Logto Cloud programaticamente, incluindo criar tenants e continuar a configuração sem precisar acessar o Console. + +Isso é útil quando você precisa provisionar tenants a partir do seu próprio fluxo de onboarding, plataforma interna, agente de IA ou automação de integração. + +O fluxo de automação é: + +1. Use um **Logto Cloud Personal Access Token (PAT)** para chamar a API do Logto Cloud. +2. Crie um tenant com `POST /api/tenants`. +3. Leia as credenciais padrão do aplicativo máquina para máquina (M2M) da resposta de criação. +4. Use o aplicativo M2M padrão para obter um token de acesso da Management API para o novo tenant. +5. Chame a Management API do novo tenant para continuar o provisionamento de aplicativos, usuários, papéis, recursos, organizações e outras configurações. + +## Antes de começar \{#before-you-start} + +Prepare os seguintes valores: + +| Variable | Description | +| -------------------- | --------------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | O endpoint da API do Logto Cloud. Para Logto Cloud, use `https://cloud.logto.io`. | +| `LOGTO_CLOUD_PAT` | Um PAT para sua conta Logto Cloud. | +| `TENANT_NAME` | O nome de exibição do tenant a ser criado. | +| `TENANT_TAG` | O tipo do tenant. Use `development` ou `production`. | +| `REGION_NAME` | O identificador da região para o tenant. | + +Defina-os como variáveis de ambiente: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="Meu tenant automatizado" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## Obter regiões disponíveis \{#get-available-regions} + +Antes de criar um tenant, busque as regiões disponíveis para sua conta Logto Cloud: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +A resposta contém as regiões disponíveis. Use o valor de `name` como `REGION_NAME` ao criar o tenant. + +Exemplo de resposta: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## Criar um tenant \{#create-a-tenant} + +Chame `POST /api/tenants` com o Logto Cloud PAT: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +A resposta inclui o tenant criado e um aplicativo M2M padrão. O aplicativo M2M é criado no novo tenant e tem acesso à Management API do tenant. + +Exemplo de resposta: + +```json +{ + "id": "new-tenant-id", + "name": "Meu tenant automatizado", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +Salve os valores necessários para o próximo passo: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## Obter um token de acesso da Management API para o novo tenant \{#get-a-management-api-access-token-for-the-new-tenant} + +Use as credenciais do aplicativo M2M padrão para solicitar um token de acesso do novo tenant: + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +Exemplo de resposta: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +Salve o token de acesso: + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## Continue o provisionamento do novo tenant \{#continue-provisioning-the-new-tenant} + +Use o token de acesso da Management API para chamar a Management API do novo tenant. + +Por exemplo, listar aplicativos: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +Ou criar um aplicativo: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "Meu aplicativo web", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +Neste ponto, sua automação pode continuar com qualquer operação da Management API, como criar usuários, aplicativos, recursos de API, papéis, organizações, conectores ou configurações da experiência de login. + +## Exemplo de automação completa \{#full-automation-example} + +O exemplo Node.js a seguir cria um tenant, troca as credenciais M2M padrão retornadas por um token de acesso da Management API e lista os aplicativos no novo tenant: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +// Criação do tenant +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'Meu tenant automatizado', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`Falha ao criar tenant: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +// Obtenção do token da Management API +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Falha ao obter token da Management API: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +// Listagem de aplicativos +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`Falha ao listar aplicativos: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## Recursos relacionados \{#related-resources} + +- [Personal access token](/user-management/personal-access-token) +- [Interagir com a Management API](/integrate-logto/interact-with-management-api) +- [Início rápido máquina para máquina](/quick-starts/m2m) diff --git a/i18n/th/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/th/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index 7342d309c90..19b48cfce06 100644 --- a/i18n/th/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/th/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,12 +3,13 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; # Logto Cloud -[Logto Cloud](https://cloud.logto.io) ให้บริการด้านการจัดการและการดำเนินงานที่หลากหลาย เพื่อช่วยให้คุณบริหารจัดการเอกลักษณ์และทรัพยากรได้อย่างราบรื่นและง่ายดาย โดยโฮสต์โดย Logto ซึ่งประกอบด้วยฟีเจอร์ต่าง ๆ เช่น [รองรับหลายภูมิภาค](/logto-cloud/tenant-settings#tenant-region), การจัดการผู้เช่า (tenant management), [การเรียกเก็บเงินและราคา](/logto-cloud/billing-and-pricing), [การจัดการสมาชิกผู้เช่า](/logto-cloud/tenant-member-management), และการควบคุมการเข้าถึงตามบทบาท (RBAC) สำหรับคอนโซล +[Logto Cloud](https://cloud.logto.io) ให้บริการด้านการจัดการและการดำเนินงานที่หลากหลาย เพื่อช่วยให้คุณจัดการเอกลักษณ์และทรัพยากรได้อย่างราบรื่นและง่ายดาย โดยโฮสต์โดย Logto ซึ่งมีฟีเจอร์ต่าง ๆ เช่น [รองรับหลายภูมิภาค](/logto-cloud/tenant-settings#tenant-region), การจัดการ tenant, [การเรียกเก็บเงินและราคา](/logto-cloud/billing-and-pricing), [การจัดการสมาชิก tenant](/logto-cloud/tenant-member-management), และการควบคุมการเข้าถึงคอนโซลตามบทบาท (RBAC) หากคุณมีคำถามเกี่ยวกับบริการคลาวด์และต้องการความช่วยเหลือเพิ่มเติม กรุณาติดต่อเรา @@ -18,28 +19,28 @@ import SystemLimit from '@site/src/assets/security.svg'; items={[ { type: 'link', - label: 'การตั้งค่าผู้เช่า', + label: 'การตั้งค่า tenant', href: '/logto-cloud/tenant-settings', - description: 'อัปเดตหรือเปลี่ยนชื่อผู้เช่า ตรวจสอบภูมิภาค และลบหรือออกจากผู้เช่า', + description: 'อัปเดตหรือเปลี่ยนชื่อ tenant, ตรวจสอบภูมิภาค, และลบหรือออกจาก tenant', customProps: { icon: , }, }, { type: 'link', - label: 'นโยบายการเก็บข้อมูลผู้เช่า Dev', + label: 'นโยบายการเก็บข้อมูล tenant สำหรับนักพัฒนา', href: '/logto-cloud/dev-tenant-data-retention', description: - 'ทำความเข้าใจนโยบายการเก็บข้อมูลผู้ใช้ 90 วันสำหรับผู้เช่า Dev และวิธีใช้ Logto dev tenant อย่างมีประสิทธิภาพ', + 'ทำความเข้าใจนโยบายการเก็บข้อมูลผู้ใช้ 90 วันสำหรับ dev tenant และวิธีใช้ Logto dev tenant อย่างมีประสิทธิภาพ', customProps: { icon: , }, }, { type: 'link', - label: 'การจัดการสมาชิกผู้เช่า', + label: 'การจัดการสมาชิก tenant', href: '/logto-cloud/tenant-member-management', - description: 'ผู้ดูแลผู้เช่าสามารถเชิญและจัดการสมาชิก รวมถึงอัปเดตบทบาทของพวกเขาได้', + description: 'ผู้ดูแล tenant สามารถเชิญและจัดการสมาชิก รวมถึงอัปเดตบทบาทของพวกเขาได้', customProps: { icon: , }, @@ -49,7 +50,7 @@ import SystemLimit from '@site/src/assets/security.svg'; label: 'โดเมนแบบกำหนดเอง', href: '/logto-cloud/custom-domain', description: - 'ใช้โดเมนของคุณเองสำหรับผู้เช่า Logto เพื่อให้ประสบการณ์ผู้ใช้ปลายทางสอดคล้องกับแบรนด์ของคุณ', + 'ใช้โดเมนของคุณเองสำหรับ Logto tenant เพื่อให้ประสบการณ์ผู้ใช้ปลายทางสอดคล้องกับแบรนด์ของคุณ', customProps: { icon: , }, @@ -68,17 +69,26 @@ import SystemLimit from '@site/src/assets/security.svg'; label: 'ขีดจำกัดของระบบ', href: '/logto-cloud/system-limit', description: - 'ทำความเข้าใจขีดจำกัดของระบบและการป้องกันอัตราสำหรับผู้เช่า Dev, Pro และ Enterprise', + 'ทำความเข้าใจขีดจำกัดของระบบและการป้องกันอัตราสำหรับ Dev, Pro, และ Enterprise tenant', customProps: { icon: , }, }, + { + type: 'link', + label: 'การจัดการ tenant อัตโนมัติ', + href: '/logto-cloud/automate-tenant-creation', + description: 'สร้างและจัดการ tenant แบบโปรแกรมด้วย Logto Cloud API และ Management API', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP Server', href: '/logto-cloud/logto-mcp-server', description: - 'เชื่อมต่อเครื่องมือ AI และ IDEs กับ Logto Cloud ผ่าน MCP เพื่อจัดการทรัพยากรและผสานรวมการยืนยันตัวตน (Authentication)', + 'เชื่อมต่อเครื่องมือ AI และ IDE กับ Logto Cloud ผ่าน MCP เพื่อจัดการทรัพยากรและผสานการยืนยันตัวตน', customProps: { icon: , }, diff --git a/i18n/th/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/th/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..988a49a17d8 --- /dev/null +++ b/i18n/th/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: จัดการผู้เช่าแบบอัตโนมัติ +sidebar_position: 8 +--- + +# จัดการผู้เช่าแบบอัตโนมัติ + +คุณสามารถจัดการผู้เช่า Logto Cloud แบบโปรแกรมมิ่งได้ รวมถึงการสร้างผู้เช่าและดำเนินการตั้งค่าต่อโดยไม่ต้องสลับไปที่ Console + +สิ่งนี้มีประโยชน์เมื่อคุณต้องการจัดเตรียมผู้เช่าจากกระบวนการ onboarding ของคุณเอง แพลตฟอร์มภายใน ตัวแทน AI หรือระบบอัตโนมัติแบบบูรณาการ + +ขั้นตอนการอัตโนมัติคือ: + +1. ใช้ **Logto Cloud Personal Access Token (PAT)** เพื่อเรียก Logto Cloud API +2. สร้างผู้เช่าด้วย `POST /api/tenants` +3. อ่านข้อมูลรับรองแอป Machine-to-machine (M2M) เริ่มต้นจากผลลัพธ์การสร้าง +4. ใช้แอป M2M เริ่มต้นเพื่อขอรับโทเค็นการเข้าถึง Management API สำหรับผู้เช่าใหม่ +5. เรียก Management API ของผู้เช่าใหม่เพื่อดำเนินการจัดเตรียมแอปพลิเคชัน ผู้ใช้ บทบาท ทรัพยากร องค์กร และการตั้งค่าอื่น ๆ ต่อไป + +## ก่อนเริ่มต้น \{#before-you-start} + +เตรียมค่าต่อไปนี้: + +| Variable | Description | +| -------------------- | --------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | จุดปลาย API ของ Logto Cloud สำหรับ Logto Cloud ใช้ `https://cloud.logto.io` | +| `LOGTO_CLOUD_PAT` | PAT สำหรับบัญชี Logto Cloud ของคุณ | +| `TENANT_NAME` | ชื่อที่แสดงของผู้เช่าที่จะสร้าง | +| `TENANT_TAG` | ประเภทของผู้เช่า ใช้ `development` หรือ `production` | +| `REGION_NAME` | ตัวระบุภูมิภาคสำหรับผู้เช่า | + +ตั้งค่าเป็น environment variables: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="My automated tenant" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## รับภูมิภาคที่มีให้เลือก \{#get-available-regions} + +ก่อนสร้างผู้เช่า ให้ดึงข้อมูลภูมิภาคที่บัญชี Logto Cloud ของคุณสามารถใช้ได้: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +ผลลัพธ์จะมีภูมิภาคที่ใช้ได้ ใช้ค่า `name` เป็น `REGION_NAME` เมื่อสร้างผู้เช่า + +ตัวอย่างผลลัพธ์: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## สร้างผู้เช่า \{#create-a-tenant} + +เรียก `POST /api/tenants` พร้อม Logto Cloud PAT: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +ผลลัพธ์จะมีข้อมูลผู้เช่าที่สร้างและแอป M2M เริ่มต้น แอป M2M นี้ถูกสร้างในผู้เช่าใหม่และมีสิทธิ์เข้าถึง Management API ของผู้เช่านั้น + +ตัวอย่างผลลัพธ์: + +```json +{ + "id": "new-tenant-id", + "name": "My automated tenant", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +บันทึกค่าที่ต้องใช้ในขั้นตอนถัดไป: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## ขอรับโทเค็นการเข้าถึง Management API สำหรับผู้เช่าใหม่ \{#get-a-management-api-access-token-for-the-new-tenant} + +ใช้ข้อมูลรับรองแอป M2M เริ่มต้นเพื่อขอโทเค็นการเข้าถึงจากผู้เช่าใหม่: + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +ตัวอย่างผลลัพธ์: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +บันทึก access token: + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## ดำเนินการจัดเตรียมผู้เช่าใหม่ต่อ \{#continue-provisioning-the-new-tenant} + +ใช้ Management API access token เพื่อเรียก Management API ของผู้เช่าใหม่ + +ตัวอย่างเช่น แสดงรายการแอปพลิเคชัน: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +หรือสร้างแอปพลิเคชัน: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "My web app", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +ในจุดนี้ ระบบอัตโนมัติของคุณสามารถดำเนินการกับ Management API ใด ๆ ต่อได้ เช่น การสร้างผู้ใช้ แอปพลิเคชัน ทรัพยากร API บทบาท องค์กร ตัวเชื่อมต่อ หรือการตั้งค่าประสบการณ์การลงชื่อเข้าใช้ + +## ตัวอย่างอัตโนมัติเต็มรูปแบบ \{#full-automation-example} + +ตัวอย่าง Node.js ต่อไปนี้จะสร้างผู้เช่า แลกเปลี่ยนข้อมูลรับรอง M2M เริ่มต้นที่ได้รับมาเป็น Management API access token และแสดงรายการแอปพลิเคชันในผู้เช่าใหม่: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'My automated tenant', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`Failed to create tenant: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Failed to get Management API token: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`Failed to list applications: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## แหล่งข้อมูลที่เกี่ยวข้อง \{#related-resources} + +- [Personal access token](/user-management/personal-access-token) +- [โต้ตอบกับ Management API](/integrate-logto/interact-with-management-api) +- [เริ่มต้น Machine-to-machine อย่างรวดเร็ว](/quick-starts/m2m) diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/zh-CN/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index 7b808d05896..899e19cceb4 100644 --- a/i18n/zh-CN/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,12 +3,13 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; # Logto Cloud -[Logto Cloud](https://cloud.logto.io) 提供了一系列管理和运营服务,帮助你顺利且轻松地管理身份和资源。由 Logto 托管,包含了如[多区域支持](/logto-cloud/tenant-settings#tenant-region)、租户管理、[计费与定价](/logto-cloud/billing-and-pricing)、[成员管理](/logto-cloud/tenant-member-management)以及控制台基于角色的访问控制等功能。 +[Logto Cloud](https://cloud.logto.io) 提供了一系列管理和运营服务,帮助你顺利且轻松地管理身份和资源。由 Logto 托管,包含了如 [多区域支持](/logto-cloud/tenant-settings#tenant-region)、租户管理、[计费与定价](/logto-cloud/billing-and-pricing)、[成员管理](/logto-cloud/tenant-member-management) 以及控制台基于角色的访问控制等功能。 如果你对云服务有任何疑问或需要额外支持,请联系我们。 @@ -56,7 +57,7 @@ import SystemLimit from '@site/src/assets/security.svg'; type: 'link', label: '计费与定价', href: '/logto-cloud/billing-and-pricing', - description: '轻松了解你的账单,自信地管理你的订阅。', + description: '轻松了解你的账单,并自信地管理你的订阅。', customProps: { icon: , }, @@ -70,6 +71,15 @@ import SystemLimit from '@site/src/assets/security.svg'; icon: , }, }, + { + type: 'link', + label: '自动化租户管理', + href: '/logto-cloud/automate-tenant-creation', + description: '通过 Logto Cloud API 和 Management API 以编程方式创建和管理租户。', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP Server', diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/zh-CN/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..cd999bb5b71 --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: 自动化租户管理 +sidebar_position: 8 +--- + +# 自动化租户管理 + +你可以通过编程方式管理 Logto Cloud 租户,包括创建租户并持续配置,无需切换到控制台 (Console)。 + +当你需要从自己的注册流程、内部平台、AI 代理或集成自动化中预配租户时,这非常有用。 + +自动化流程如下: + +1. 使用 **Logto Cloud 个人访问令牌 (PAT)** 调用 Logto Cloud API。 +2. 使用 `POST /api/tenants` 创建租户。 +3. 从创建响应中读取默认机器对机器 (M2M) 应用程序凭据。 +4. 使用默认 M2M 应用程序为新租户获取 Management API 访问令牌 (Access token)。 +5. 调用新租户的 Management API,继续预配应用程序、用户、角色 (Roles)、资源 (API 资源)、组织 (Organizations) 及其他设置。 + +## 开始前的准备 \{#before-you-start} + +准备以下值: + +| Variable | Description | +| -------------------- | ----------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | Logto Cloud API 端点。对于 Logto Cloud,使用 `https://cloud.logto.io`。 | +| `LOGTO_CLOUD_PAT` | 你的 Logto Cloud 账户的 PAT。 | +| `TENANT_NAME` | 要创建的租户显示名称。 | +| `TENANT_TAG` | 租户类型。使用 `development` 或 `production`。 | +| `REGION_NAME` | 租户的区域标识符。 | + +将它们设置为环境变量: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="我的自动化租户" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## 获取可用区域 \{#get-available-regions} + +在创建租户之前,获取你的 Logto Cloud 账户可用的区域: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +响应中包含可用区域。在创建租户时,使用 `name` 的值作为 `REGION_NAME`。 + +示例响应: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## 创建租户 \{#create-a-tenant} + +使用 Logto Cloud PAT 调用 `POST /api/tenants`: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +响应中包含已创建的租户和一个默认的 M2M 应用程序。该 M2M 应用程序在新租户中创建,并有权访问该租户的 Management API。 + +示例响应: + +```json +{ + "id": "new-tenant-id", + "name": "我的自动化租户", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +保存你在下一步需要的值: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## 获取新租户的 Management API 访问令牌 (Access token) \{#get-a-management-api-access-token-for-the-new-tenant} + +使用默认 M2M 应用程序凭据,从新租户请求访问令牌 (Access token): + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +示例响应: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +保存访问令牌 (Access token): + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## 继续预配新租户 \{#continue-provisioning-the-new-tenant} + +使用 Management API 访问令牌 (Access token) 调用新租户的 Management API。 + +例如,列出应用程序: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +或者创建一个应用程序: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "我的 Web 应用", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +此时,你的自动化可以继续进行任何 Management API 操作,例如创建用户、应用程序、API 资源、角色 (Roles)、组织 (Organizations)、连接器 (Connectors) 或登录体验设置。 + +## 完整自动化示例 \{#full-automation-example} + +以下 Node.js 示例会创建一个租户,使用返回的默认 M2M 凭据换取 Management API 访问令牌 (Access token),并列出新租户中的应用程序: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: '我的自动化租户', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`创建租户失败: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`获取 Management API 令牌失败: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`列出应用程序失败: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## 相关资源 \{#related-resources} + +- [个人访问令牌 (Personal access token)](/user-management/personal-access-token) +- [与 Management API 交互](/integrate-logto/interact-with-management-api) +- [机器对机器 (Machine-to-machine) 快速开始](/quick-starts/m2m) diff --git a/i18n/zh-TW/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx b/i18n/zh-TW/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx index 647ec36dd07..585f77dff11 100644 --- a/i18n/zh-TW/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx +++ b/i18n/zh-TW/docusaurus-plugin-content-docs/current/logto-cloud/README.mdx @@ -3,6 +3,7 @@ import Developer from '@site/src/assets/developer.svg'; import TenantMemberManagement from '@site/src/assets/gear.svg'; import PricingAndBilling from '@site/src/assets/key.svg'; import McpIcon from '@site/src/assets/mcp.svg'; +import TenantAutomation from '@site/src/assets/robot.svg'; import CustomDomains from '@site/src/assets/search.svg'; import SystemLimit from '@site/src/assets/security.svg'; @@ -10,7 +11,7 @@ import SystemLimit from '@site/src/assets/security.svg'; [Logto Cloud](https://cloud.logto.io) 提供一系列管理與營運服務,協助你順利且輕鬆地管理身分 (Identities) 與資源 (Resources)。由 Logto 託管,包含 [多區域支援](/logto-cloud/tenant-settings#tenant-region)、租戶管理、[計費與價格](/logto-cloud/billing-and-pricing)、[成員管理](/logto-cloud/tenant-member-management) 以及主控台角色型存取控制 (RBAC, Role-based Access Control) 等功能。 -若你對雲端服務有任何疑問或需要額外支援,歡迎聯繫我們。 +若你對雲端服務有任何疑問或需要額外協助,歡迎聯繫我們。 ## 雲端服務功能 \{#features-for-cloud-service} @@ -20,7 +21,7 @@ import SystemLimit from '@site/src/assets/security.svg'; type: 'link', label: '租戶設定 (Tenant settings)', href: '/logto-cloud/tenant-settings', - description: '更新或變更租戶名稱、檢查區域、刪除或退出租戶。', + description: '更新或變更租戶名稱、檢查區域,並刪除或退出租戶。', customProps: { icon: , }, @@ -38,7 +39,7 @@ import SystemLimit from '@site/src/assets/security.svg'; type: 'link', label: '租戶成員管理 (Tenant member management)', href: '/logto-cloud/tenant-member-management', - description: '租戶管理員可邀請與管理成員,並更新其角色 (Roles)。', + description: '租戶管理員可邀請與管理成員,並更新其角色 (Role)。', customProps: { icon: , }, @@ -56,7 +57,7 @@ import SystemLimit from '@site/src/assets/security.svg'; type: 'link', label: '計費與價格 (Billing and pricing)', href: '/logto-cloud/billing-and-pricing', - description: '輕鬆瞭解帳單並自信管理你的訂閱。', + description: '輕鬆瞭解你的帳單,並自信地管理訂閱。', customProps: { icon: , }, @@ -70,6 +71,15 @@ import SystemLimit from '@site/src/assets/security.svg'; icon: , }, }, + { + type: 'link', + label: '自動化租戶管理 (Automate tenant management)', + href: '/logto-cloud/automate-tenant-creation', + description: '透過 Logto Cloud API 與 Management API 以程式化方式建立與管理租戶。', + customProps: { + icon: , + }, + }, { type: 'link', label: 'Logto MCP Server', diff --git a/i18n/zh-TW/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx b/i18n/zh-TW/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx new file mode 100644 index 00000000000..16ade1f7956 --- /dev/null +++ b/i18n/zh-TW/docusaurus-plugin-content-docs/current/logto-cloud/automate-tenant-creation.mdx @@ -0,0 +1,242 @@ +--- +id: automate-tenant-creation +title: 自動化租戶管理 +sidebar_position: 8 +--- + +# 自動化租戶管理 + +你可以透過程式化方式管理 Logto Cloud 租戶,包括建立租戶並持續進行設定,無需切換至 Console。 + +這在你需要從自己的導入流程、內部平台、AI agent 或整合自動化中佈建租戶時非常有用。 + +自動化流程如下: + +1. 使用 **Logto Cloud Personal Access Token (PAT)** 呼叫 Logto Cloud API。 +2. 透過 `POST /api/tenants` 建立租戶。 +3. 從建立回應中讀取預設機器對機器 (M2M) 應用程式憑證。 +4. 使用預設 M2M 應用程式為新租戶取得 Management API 存取權杖 (Access token)。 +5. 呼叫新租戶的 Management API,持續佈建應用程式、使用者、角色 (Roles)、資源 (Resources)、組織 (Organizations) 及其他設定。 + +## 開始前的準備 \{#before-you-start} + +請準備以下數值: + +| Variable | Description | +| -------------------- | ------------------------------------------------------------------------- | +| `CLOUD_API_ENDPOINT` | Logto Cloud API 端點。對於 Logto Cloud,請使用 `https://cloud.logto.io`。 | +| `LOGTO_CLOUD_PAT` | 你的 Logto Cloud 帳號的 PAT。 | +| `TENANT_NAME` | 要建立的租戶顯示名稱。 | +| `TENANT_TAG` | 租戶型態。請使用 `development` 或 `production`。 | +| `REGION_NAME` | 租戶的區域識別碼。 | + +將它們設為環境變數: + +```bash +export CLOUD_API_ENDPOINT="https://cloud.logto.io" +export LOGTO_CLOUD_PAT="" +export TENANT_NAME="My automated tenant" +export TENANT_TAG="development" +export REGION_NAME="" +``` + +## 取得可用區域 \{#get-available-regions} + +在建立租戶前,先查詢你的 Logto Cloud 帳號可用的區域: + +```bash +curl "$CLOUD_API_ENDPOINT/api/me/regions" \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" +``` + +回應內容包含可用區域。建立租戶時,請將 `name` 欄位作為 `REGION_NAME` 使用。 + +範例回應: + +```json +{ + "regions": [ + { + "name": "EU", + "displayName": "Europe" + }, + { + "name": "US", + "displayName": "United States" + } + ] +} +``` + +## 建立租戶 \{#create-a-tenant} + +使用 Logto Cloud PAT 呼叫 `POST /api/tenants`: + +```bash +curl "$CLOUD_API_ENDPOINT/api/tenants" \ + -X POST \ + -H "Authorization: Bearer $LOGTO_CLOUD_PAT" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "'"$TENANT_NAME"'", + "tag": "'"$TENANT_TAG"'", + "regionName": "'"$REGION_NAME"'" + }' +``` + +回應內容包含已建立的租戶及預設 M2M 應用程式。該 M2M 應用程式建立於新租戶中,並擁有該租戶的 Management API 存取權。 + +範例回應: + +```json +{ + "id": "new-tenant-id", + "name": "My automated tenant", + "tag": "development", + "indicator": "https://new-tenant-id.logto.app", + "regionName": "EU", + "defaultApplication": { + "id": "default-m2m-app-id", + "secret": "default-m2m-app-secret" + } +} +``` + +將你需要的值儲存以供下一步使用: + +```bash +export TENANT_ID="" +export TENANT_ENDPOINT="" +export DEFAULT_M2M_APP_ID="" +export DEFAULT_M2M_APP_SECRET="" +``` + +## 取得新租戶的 Management API 存取權杖 (Access token) \{#get-a-management-api-access-token-for-the-new-tenant} + +使用預設 M2M 應用程式憑證,向新租戶請求存取權杖: + +```bash +curl "$TENANT_ENDPOINT/oidc/token" \ + -X POST \ + -u "$DEFAULT_M2M_APP_ID:$DEFAULT_M2M_APP_SECRET" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + -d "grant_type=client_credentials" \ + -d "resource=$TENANT_ENDPOINT/api" \ + -d "scope=all" +``` + +範例回應: + +```json +{ + "access_token": "eyJ...", + "expires_in": 3600, + "token_type": "Bearer", + "scope": "all" +} +``` + +儲存存取權杖: + +```bash +export MANAGEMENT_API_ACCESS_TOKEN="" +``` + +## 持續佈建新租戶 \{#continue-provisioning-the-new-tenant} + +使用 Management API 存取權杖呼叫新租戶的 Management API。 + +例如,列出應用程式: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" +``` + +或建立一個應用程式: + +```bash +curl "$TENANT_ENDPOINT/api/applications" \ + -X POST \ + -H "Authorization: Bearer $MANAGEMENT_API_ACCESS_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "My web app", + "type": "SPA", + "oidcClientMetadata": { + "redirectUris": ["https://example.com/callback"], + "postLogoutRedirectUris": ["https://example.com"] + } + }' +``` + +此時,你的自動化流程可以繼續進行任何 Management API 操作,例如建立使用者、應用程式、API 資源 (API resources)、角色 (Roles)、組織 (Organizations)、連接器 (Connectors) 或登入體驗設定。 + +## 完整自動化範例 \{#full-automation-example} + +以下 Node.js 範例會建立租戶、用回傳的預設 M2M 憑證換取 Management API 存取權杖,並列出新租戶中的應用程式: + +```js +const cloudApiEndpoint = 'https://cloud.logto.io'; +const logtoCloudPat = process.env.LOGTO_CLOUD_PAT; + +const createTenantResponse = await fetch(`${cloudApiEndpoint}/api/tenants`, { + method: 'POST', + headers: { + authorization: `Bearer ${logtoCloudPat}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + name: 'My automated tenant', + tag: 'development', + regionName: 'EU', + }), +}); + +if (!createTenantResponse.ok) { + throw new Error(`Failed to create tenant: ${await createTenantResponse.text()}`); +} + +const tenant = await createTenantResponse.json(); +const tenantEndpoint = tenant.indicator; +const { id: appId, secret: appSecret } = tenant.defaultApplication; + +const tokenResponse = await fetch(`${tenantEndpoint}/oidc/token`, { + method: 'POST', + headers: { + authorization: `Basic ${Buffer.from(`${appId}:${appSecret}`).toString('base64')}`, + 'content-type': 'application/x-www-form-urlencoded', + }, + body: new URLSearchParams({ + grant_type: 'client_credentials', + resource: `${tenantEndpoint}/api`, + scope: 'all', + }), +}); + +if (!tokenResponse.ok) { + throw new Error(`Failed to get Management API token: ${await tokenResponse.text()}`); +} + +const { access_token: managementApiAccessToken } = await tokenResponse.json(); + +const applicationsResponse = await fetch(`${tenantEndpoint}/api/applications`, { + headers: { + authorization: `Bearer ${managementApiAccessToken}`, + }, +}); + +if (!applicationsResponse.ok) { + throw new Error(`Failed to list applications: ${await applicationsResponse.text()}`); +} + +const applications = await applicationsResponse.json(); + +console.log({ tenantId: tenant.id, applications }); +``` + +## 相關資源 \{#related-resources} + +- [Personal access token](/user-management/personal-access-token) +- [與 Management API 互動](/integrate-logto/interact-with-management-api) +- [機器對機器快速入門](/quick-starts/m2m)