0

I'm developing an app, which should connect to an external DocumentDB database (not mine). The app is build with Cordova/Ionic.

I founda JavaScript library from Microsoft Azure in order to ensure a DocumentDB database connection, but it is asking for some weird stuff like collection_rid and tokens.

I've got the following from the guys of the external DocumentDB database:

But how am I supposed to retrieve the collection_rid and token from this information?

2 Answers 2

1

Without row-level authorization, DocumentDB is designed to be accessed from a server-side app, not directly from javascript in the browser. When you give it the master token, you get full access which is generally not what you want for your end-user clients. Even the read-only key is usually not what you want to hand out to your clients. The Azure-provided javascript library is designed to be run from node.js as your server-side app.

That said, if you really want to access it from the browser without a proxy app running on a server, you can definitely do so using normal REST calls directly hitting the DocumentDB REST API. I do not think the Azure-provided SDK will run directly in the browser, but with help from Browserify and some manual tweaking (it's open source) you may be able to get it to run.

You can get the collection name from the same folks who provided you the connection string information and use name-based routing to access the collection. I'm not sure exactly what you mean by token but I'm guessing that you are referring to the session token (needed for session-level consistency). Look at the REST API specs if you want to know the details about how that token gets passed back and forth (in HTTP headers) but it's automatically taken care of by the SDKs if you go that route.

Sign up to request clarification or add additional context in comments.

5 Comments

So you are saying that I'm able to retrieve the data through normal REST API calls? That would be perfect. I just want to read the data in order to show them in the app, actually I don't want to deal with this (for me) new kind of database, and all the security layers, and node.js, etc. How can I retrieve the data via REST APIs from DocumentDB? With normal POST or GET requests? I've got the complete Web API documentation of this database.
If you found this answer satisfactory, can you please accept the answer?
thanks. yes i will accept your answer, but i have to dig into this topic a little bit deeper. maybe you know a short answer to it, but is it possible to make a ordinary ajax request (GET) to retrieve the data?
Absolutely. That's what the REST API is for. The tricky part is composing the authorization header but there are plenty of answers here on SO explaining how to do that.
0

Please note that DocumentDB also provides support equivalent to row-level authorization by enabling you to create specific permissions on the desired entities. Once you have such a permission, you can retrieve the corresponding token, which is scoped to be valid for a certain time period. You would need to set up a mid-tier that can fetch these tokens and distribute to your user application. The user application can then use these tokens as bearer-tokens instead of using the master key.

You can find more details at https://msdn.microsoft.com/en-us/library/azure/dn783368.aspx

https://msdn.microsoft.com/en-us/library/azure/7298025b-bcf1-4fc7-9b54-6e7ca8c64f49

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.