Microsoft.Azure.Management.ApiManagement Implementation

前端 未结 3 626
北恋
北恋 2021-01-24 10:25

I am trying to implement Azure API Management APIs using Microsoft.Azure.Management.ApiManagement 4.0.4-preview.

No where I see documentation for implementa

3条回答
  •  一整个雨季
    2021-01-24 10:33

    @Joseph, I had the same issue with unauthorized responses. Inspected the request made through the ApiManagementClient. Two things were wrong:

    1. Wrong url
    2. Missing authorization header.

    Corrected this by doing:

    var credentials = new MyCredentials();
    var client = new ApiManagementClient(new Uri("https://management.azure.com/"), credentials);
    client.SubscriptionId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
    client.HttpClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + credentials.AuthenticationToken);
    var result = await client.User.ListByServiceAsync("resource-group", "service");
    

    MyCredentials looks the same as the myServiceCredentials class in the previous response and it inherits from ServiceClientCredentials. Had to make the AuthenticationToken prop public though.

提交回复
热议问题