It took me some time to figure it out. Here is a howto to proxy from an Azure API Management to Cosmos DB.
Note down some point from your Cosmos Environment.
In my case we have the
URL https://fellowtest.documents.azure.com
Collections Id Items
Database ToDoList
We need this point later in the script. Go the Key section and write down the Primary Key:
Now open your API Management.
Enter here the Values
Now click on API and add a black API
Do not forget Products here.
Create a new operation
Select your new policy and click on to open the editor
Add the policy
[code]
@{
bool idBased = true;
var date = context.Variables.GetValueOrDefault("requestDateString");
var databaseId = "ToDoList";
var collectionId = "Items";
var verb = "GET";
var resourceType = "docs";
//var resourceLink = string.Format("dbs/{0}/colls/{1}/docs", databaseId, collectionId);
var resourceId = string.Format("dbs/{0}/colls/{1}", databaseId, collectionId);
var key = context.Variables.GetValueOrDefault("cosmoskey");
var keyType="master";
var tokenVersion="1.0";
var hmacSha256 = new System.Security.Cryptography.HMACSHA256 { Key = Convert.FromBase64String(key) };
verb = verb ?? "";
resourceType = resourceType ?? "";
resourceId = resourceId ?? "";
string payLoad = string.Format("{0}\n{1}\n{2}\n{3}\n{4}\n",
verb.ToLowerInvariant(),
resourceType.ToLowerInvariant(),
resourceId,
date.ToLowerInvariant(),
""
);
byte[] hashPayLoad = hmacSha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(payLoad));
string signature = Convert.ToBase64String(hashPayLoad);
return System.Uri.EscapeDataString(String.Format("type={0}&ver={1}&sig={2}",
keyType,
tokenVersion,
signature));
}
application/query+json
True
@(context.Variables.GetValueOrDefault("requestDateString"))
2017-02-22
true
@(context.LastError.Source)
@(context.LastError.Reason)
@(context.LastError.Message)
@(context.LastError.Scope)
@(context.LastError.Section)
@(context.LastError.Path)
@(context.LastError.PolicyId)
@(context.Response.StatusCode.ToString())
[/code]
Now the point you need to change are:
var databaseId = "ToDoList";
var collectionId = "Items";
Click now on Test
Now write down the Public IP from your API Managment
Go back to Cosmos DB and click on Firewall
Your Cosmos is now protected
In the past, companies were particularly successful when they were ahead of their customers’ wishes. Those who had already thought of tomorrow were well supplied with customers in TODAY. Digitalization is changing the world and its habits. Even though digital transformation is a topic of the future, it is much more about being here and […]
We wanted to develop a easy to use CTI Plugin for SugarCRM. Our solution use Twilio. We a few clicks it is possible to configure the plugin and User can use the browser to call out and receive calls. If you wanted to use CTI without a big hassle then please contact us.
Schaut man sich die Berichte der letzten Monate an, so sieht es oft so aus, als ob Ende dieses Jahres die elektronische Rechnung endgültig Einzug gehalten hat. Doch nicht zuletzt aufgrund des föderalen Systems in Deutschland ist dem nicht so.