Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
342 stars 44 forks source link

Problem using Cosmos Resource Tokens #123

Closed andyevans2000 closed 4 years ago

andyevans2000 commented 4 years ago

Great library, which I use a lot!

Just starting using resource tokens and am having issues. I can generate a user, a permission for a container and a resource token for that user. I can use the token to write items to the container using the Microsoft.Azure.Cosmos library. However when I use Cosmonaut to do the same thing to the same container I get a Forbidden response with "Insufficient permissions provided in the authorization header for the corresponding request. Please retry with another authorization header." This works when when I use the master key.

This is the line that throws the error cosmosStore = new CosmosStore(new CosmonautClient(DatabaseUri, token), DatabaseName, container);

I am using the shared collection feature of Cosmonaut.

Not sure if this is a bug or if I am missing something so any ideas are appreciated.

andyevans2000 commented 4 years ago

The reason for this is the ProvisionInfrastructureIfMissing property defaults to true and needs to be set to false when using resource tokens. This is because the resource token won't have permissions to check if the containers / database exists and throws an exception.