Hi everyone
we need to know steps to create a user to connect in cosmos db.
How i create a user to access and read documents on cosmosdb ?
I don't want the user using connection string with user which is on the blade
Hi everyone
we need to know steps to create a user to connect in cosmos db.
How i create a user to access and read documents on cosmosdb ?
I don't want the user using connection string with user which is on the blade
Hi @WilianJoseLima-7953 , please let us know if you need more details on the same. If answer helped, you can accept the answer.
Hi @WilianJoseLima-7953, welcome to Microsoft Q&A forum.
You can refer to below documentation to create and assign necessary permissions to users:
Secure access to data in Azure Cosmos DB
Creating a User:
//Create a user.
Database database = benchmark.client.GetDatabase("SalesDatabase");
User user = await database.CreateUserAsync("User 1");
Creating Permission:
// Create a permission on a container and specific partition key value
Container container = client.GetContainer("SalesDatabase", "OrdersContainer");
user.CreatePermissionAsync(
new PermissionProperties(
id: "permissionUser1Orders",
permissionMode: PermissionMode.All,
container: container,
resourcePartitionKey: new PartitionKey("012345")));
Code sample to read permission for user:
//Read a permission, create user client session.
PermissionProperties permissionProperties = await user.GetPermission("permissionUser1Orders")
CosmosClient client = new CosmosClient(accountEndpoint: "MyEndpoint", authKeyOrResourceToken: permissionProperties.Token);
You can find the rest api and the permissions in below link as well:
https://docs.microsoft.com/en-us/rest/api/cosmos-db/users
https://docs.microsoft.com/en-us/rest/api/cosmos-db/permissions
Please let me know if this helps.
If answer helps, please mark it 'Accept Answer'
5 people are following this question.