Microsoft.Azure.Management.ApiManagement Implementation

前端 未结 3 732
北恋
北恋 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:40

    After two weeks struggle we found way to Microsoft.Azure.Management.ApiManagement dll Implementation.

    1) Create application inside azure ad 2) Go to your APIM => Access control (IAM) Tab 3) Add the above created application (permission is required to do this in APIM) 4) Now you should be able to see Azure AD application in APIM Access control (IAM) Tab

    This will provide delegated permission to your application which is created in Azure AD

    We can use client credential flow to get delegated access token against Azure AD. Use scope as https://management.azure.com

    The sample code for implementing client credential flow for Microsoft.Azure.Management.ApiManagement dll is given below.

    public class myServiceCredentials : ServiceClientCredentials{
    private string AuthenticationToken { get; set; }
    public override void InitializeServiceClient(ServiceClient client)
        {
            var authenticationContext = new 
       AuthenticationContext("https://login.windows.net/{tenantID}");
            var credential = new ClientCredential(clientId: "xxxxx-xxxx-xx-xxxx-xxx", 
      clientSecret: "{clientSecret}");
            var result = authenticationContext.AcquireToken(resource: 
            "https://management.core.windows.net/", clientCredential: credential);
    
            if (result == null)
            {
                throw new InvalidOperationException("Failed to obtain the JWT token");
            }
            AuthenticationToken = result.AccessToken;
        }
    }
    

    Thank you https://github.com/Azure/azure-sdk-for-net/issues/4727

提交回复
热议问题