Si usa cuentas de servicio, se requiere un token para realizar solicitudes a la API de administración de Atlas. Para obtener más información, consulte Descripción general de las cuentas de servicio.
Nota
Las listas de acceso IP se aplican al uso de tokens de acceso de cuentas de servicio, no creándolos o revocándolos. Puedes generar un token desde cualquier dirección IP, pero solo puedes usarlo para llamar al API si tu dirección IP está en la lista de acceso.
Resource
POST https://cloud.mongodb.com/api/oauth/token
Parámetros de la ruta de solicitud
Este endpoint no utiliza parámetros de ruta de solicitud HTTP.
Parámetros de Solicitud Query
Los siguientes parámetros de query son opcionales:
Nombre | Tipo | Necesidad | Descripción | predeterminado |
|---|---|---|---|---|
bonito | booleano | Opcional | Indicador que señala si el cuerpo de la respuesta debe estar en formato prettyprint. |
|
envelope | booleano | Opcional | Bandera que indica si se debe o no envolver la respuesta en un sobre. Algunos clientes de API no pueden acceder a los encabezados de respuesta HTTP ni al código de estado. Para solucionarlo, configure Para los endpoints que devuelven una lista de resultados, el objeto |
|
Parámetros del cuerpo de la solicitud
Este endpoint no utiliza parámetros de cuerpo de solicitud HTTP.
Respuesta
La respuesta incluye:
Nombre | Tipo | Descripción |
|---|---|---|
token de acceso | string | El token de acceso a la cuenta de servicio para autenticar solicitudes de API. |
token_type | string | El mecanismo para la autorización de token, aquí representado como |
expira en | entero | La duración durante la cual el token de acceso es válido, en segundos. |
Solicitud de ejemplo
Reemplaza {BASE64-AUTH} en el siguiente ejemplo con tu ID de cliente de la cuenta de servicio codificado en base64y el secreto. Para obtener más información, consulte Realizar una API solicitud.
curl --request POST \ --url https://cloud.mongodb.com/api/oauth/token \ --header 'accept: application/json' \ --header 'cache-control: no-cache' \ --header 'authorization: Basic {BASE64-AUTH}' \ --header 'content-type: application/x-www-form-urlencoded' \ --data 'grant_type=client_credentials'
Respuesta de ejemplo
Encabezado de respuesta
200 OK date: {dateInUnixFormat} strict-transport-security: max-age=31536000; includeSubdomains; vary: Accept-Encoding content-type: application/vnd.atlas.{apiVersion}+json;charset=utf-8 referrer-policy: strict-origin-when-cross-origin x-permitted-cross-domain-policies: none x-content-type-options: nosniff x-mongodb-service-version: gitHash={gitHash}; versionString={applicationVersion} x-frame-options: DENY content-length: {requestLengthInBytes} x-envoy-upstream-service-time: 44 server: mdbws
400 Bad Request Date: {dateInUnixFormat} Content-Type: application/json Content-Length: {requestLengthInBytes} Server: mdbws Strict-Transport-Security: max-age=31536000; includeSubdomains; X-MongoDB-Service-Version: gitHash={gitHash}; versionString={ApplicationVersion} ...
401 Unauthorized Content-Type: application/json;charset=ISO-8859-1 Date: {dateInUnixFormat} WWW-Authenticate: Digest realm="MMS Public API", domain="", nonce="{nonce}", algorithm=MD5, op="auth", stale=false Content-Length: {requestLengthInBytes} Connection: keep-alive
403 Forbidden Vary: Accept-Encoding Content-Type: application/json Strict-Transport-Security: max-age=300 Date: {dateInUnixFormat} Connection: keep-alive Content-Length: {requestLengthInBytes} X-MongoDB-Service-Version: gitHash={gitHash}; versionString={ApplicationVersion} ...
429 Too Many Requests Retry-After: {retryAfterValue} Vary: Accept-Encoding Content-Type: application/json Strict-Transport-Security: max-age=300 Date: {dateInUnixFormat} Connection: keep-alive Content-Length: {requestLengthInBytes} X-MongoDB-Service-Version: gitHash={gitHash}; versionString={ApplicationVersion} ...
500 Internal Server Error Vary: Accept-Encoding Content-Type: application/json Strict-Transport-Security: max-age=300 Date: {dateInUnixFormat} Content-Length: {requestLengthInBytes} X-MongoDB-Service-Version: gitHash={gitHash}; versionString={ApplicationVersion} ...
503 Service Unavailable Retry-After: {retryAfterValue} Vary: Accept-Encoding Content-Type: application/json Strict-Transport-Security: max-age=300 Date: {dateInUnixFormat} Content-Length: {requestLengthInBytes} X-MongoDB-Service-Version: gitHash={gitHash}; versionString={ApplicationVersion} ...
Respuesta del cuerpo
{ "access_token":"eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXVCIsImtpZCI6IjAwMDAwMDAwLTQwMDBtLTQ0MGEIXkY0IH4IMF84MGYMX2FtperB2miniFzHCJ9.eyJpc3MiOiJodHRwczUvYWxkZXYubW9uZ29kYi5jb20iLCJhdWQiOiJhcGk6Ly9hZG1pbiIsInN1YiI6ImZha2Vfc3ViX2lkXzAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwic2lkIjoiZmFrZTNfaWRfMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIiwic2Vzc2lvblN1YiI6ImZha2Vfc2lkXzAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwIIDmVlc1NX4adGVyaCBJRCJvbmcxISS8zdeD0pyQwMjNlIiwiYWN0b3JJZCI6ImZha2Vfc2lkXzAwMDAwMDAwMDAwMDOIi8wMDAwMDAwMCIsImlhdCI6MTIzNDU2Nzg5MCwiZXhwIjoxMjM0NTc0OTgwLCJqdGkiOiJmYWtlLWp0aS02MOwNDBQNDBdDOGhyES8xOTY1OGEtMDAwMDAwMDAwMDAwMDAwMDAwMGIwNjRGM3NifQ==.jmbo9d_fgfk32FGB423f09SF0kFSDFoQxh3j9FZ2", "expires_in":3600, "token_type":"Bearer" }
{ "error_description": "The provided credentials are not valid.", "error": "invalid_request" }
{ "error_description": "Invalid grant type.", "error": "unsupported_grant_type" }
{ "error_description": "Invalid grant.", "error": "invalid_grant" }
{ "error_description": "Invalid credentials provided.", "error": "invalid_client" }
{ "error_description": "IP access list validation failed for the service account.", "error": "access_denied" }
{ "error_description": "Resource {URL} is limited to 10 requests every 1 minutes.", "error": "rate_limited" }
{ "error_description": "Unexpected error.", "error": "server_error" }