question

WilianJoseLima-7953 avatar image
0 Votes"
WilianJoseLima-7953 asked AnuragSharma-MSFT commented

Steps to create a single user

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


azure-cosmos-db
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @WilianJoseLima-7953 , please let us know if you need more details on the same. If answer helped, you can accept the answer.

0 Votes 0 ·

1 Answer

AnuragSharma-MSFT avatar image
0 Votes"
AnuragSharma-MSFT answered

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 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.