Es hat einige Zeit gedauert, dies herauszufinden.
Notieren Sie sich einige Punkte aus Ihrer Cosmos-Umgebung
In meinem Fall haben wir:
URL https://fellowtest.documents.azure.com
Collections Id Elemente
Datenbank ToDoListe
Wir werden dies später im Skript benötigen. Gehen Sie zur “Key section” und notieren Sie den Hauptschlüßel.
Jetzt öffnen Sie Ihr API Management.
Setzen Sie hier die Werte ein.
Jetzt klicken Sie auf “API” und fügen “black API” hinzu.
Vergessen Sie hier nicht die Produkte.
Erstellen Sie eine neue “operation”.
Wählen Sie nun “new policy” und klicken Sie auf “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