Docs Menu
Docs Home
/ /

Generar token de cuenta de servicio

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 cuentas de servicio.

Nota

Las listas de acceso de IP se aplican al uso de tokens de acceso a cuentas de servicio, no crearlos o revocarlos. Puedes generar un token desde cualquier dirección IP, pero solo puedes usarlo para llamar a API si su dirección IP está en la lista de acceso.

POST https://cloud.mongodb.com/api/oauth/token

Este punto final no utiliza parámetros de ruta de solicitud HTTP.

Los siguientes parámetros de consulta son opcionales:

Nombre
Tipo
Necesidad
Descripción
predeterminado

bonita

booleano

Opcional

Bandera que indica si el cuerpo de la respuesta debe estar en formato prettyprint.

false

envolvente

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 envelope : true en la consulta.

Para los puntos finales que devuelven una lista de resultados, el objeto content es un sobre. Atlas añade el campo status al cuerpo de la respuesta.

false

Este punto final no utiliza parámetros del cuerpo de la solicitud HTTP.

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 de autorización de token, aquí representado como Bearer.

caduca en

entero

La duración de validez del token de acceso, en segundos.

En el siguiente ejemplo, reemplaza por {BASE64-AUTH} 64el ID de cliente y el secreto de tu cuenta de servicio codificados en base. Para obtener más información, consulta Realizar una solicitud de API.

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'
HTTP/2 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
HTTP/1.1 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}
...
HTTP/1.1 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
HTTP/1.1 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}
...
HTTP/1.1 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}
...
HTTP/1.1 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}
...
HTTP/1.1 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}
...
{
"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"
}

Volver

Acciones de roles personalizadas

En esta página