生成服务帐户令牌
2024 年 8 月 30 日以后,Cloud Manager 将不再支持 MongoDB 3.6 和 4.0 的自动化、备份和监控。请升级您的 MongoDB 部署或迁移到 Atlas。
Resource
POST https://cloud.mongodb.com/api/oauth/token
请求路径参数
此端点不使用 HTTP 请求路径参数。
请求查询参数
以下查询参数为可选参数:
名称 | 类型 | 必要性 | 说明 | 默认 |
---|---|---|---|---|
pretty | 布尔 | Optional | 指示响应正文是否应采用 美观打印 的标志 格式。 |
|
envelope | 布尔 | Optional | 指示是否将响应包装在信封中的标志。 某些 API 客户端无法访问 HTTP 响应标头或状态代码。要修复此问题,在查询中设置 对于返回结果列表的端点, |
|
backupJobsEnabledOnly | 布尔 | Optional | 指示是否从响应中排除未启用备份数据库的守护进程的标志。 将其设置为 |
|
请求正文参数
此端点不使用 HTTP 请求正文参数。
响应
响应包括:
名称 | 类型 | 说明 |
---|---|---|
access_token | 字符串 | 用于对API请求进行身份验证的服务帐户访问权限令牌。 |
token_type | 字符串 | 令牌授权机制,在此处表示为 |
expires_in | 整型 | 访问权限令牌的有效持续时间(以秒为单位)。 |
请求示例
将以下示例中的 {BASE64-AUTH}
替换为基本 64 编码的服务帐户客户端ID和密钥。要学习;了解更多信息,请参阅发出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'
响应示例
响应标头
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}
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} ...
响应体
{ "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" }