Docs Menu
Docs Home
/ /

Generar token de cuenta de servicio

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

false

envolvente

booleano

Opcional

Bandera que indica si se debe o no envolver la respuesta en un sobre.

Algunos Los clientes de laAPI no pueden acceder a los encabezados de respuesta HTTP ni al código de estado. Para solucionar esto, configure envelope : true en la consulta.

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

false

trabajos de respaldo habilitados solamente

booleano

Opcional

Indicador que indica si se deben excluir de la respuesta los daemons no habilitados para realizar copias de seguridad de bases de datos. Establezca este valor en false para incluir las configuraciones de daemon con el indicador backupJobsEnabled establecido en false.

true

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.

Reemplace {BASE64-AUTH} en el siguiente ejemplo con el ID de cliente y el secreto de su cuenta de servicio codificados con la base64. Para obtener más información, consulte 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/1.1 200 OK
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 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

Cuentas de servicio

En esta página