Secure MongoDB Atlas: AuthN and AuthZ / Implement Secure Authentication and Authorization

Code Summary: Authorization in Atlas

Below is an overview of the code that invites a new user to an Atlas organization.

Prerequisites

  • Atlas organization ID
  • Atlas Admin API

Usage

Invite a user to an Atlas organization:

Update the {orgId} and {groupId} with your credentials.

curl --user "{public key}:{private key}" --digest \
  --header "Accept: application/json" \
  --header "Content-Type: application/json" \
  --include \
  --request POST\
  "https://cloud.mongodb.com/api/atlas/v2/orgs/{orgId}/users" \
  --data '
    "roles": {
    "groupRoleAssignments": [
      {
        "groupId": {groupId},
        "groupRoles": [
          "GROUP_CLUSTER_MANAGER"
        ]
      }
    ],
    "orgRoles": [
      "ORG_MEMBER"
    ]
  },
  "username": "user@example.com"
}'

NOTE: The groupId is the same as projectId.