Using authentication token in azure sdk fluent

前端 未结 3 1727
别那么骄傲
别那么骄傲 2021-02-05 14:27

To authenticate with Azure in azure sdk fluent nuget, there is a method that uses client id and secret as below

var azureCredentials = new AzureCredentials(new 
         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-05 15:21

    Is there any interface where authentication token (JWT) can be used instead of using client id and secret while creating IAzure in the below code?

    In short no. Base on my experence, if we want to access the corresponding Azure resources then we need to get the authentication token (JWT) from the corresponding resources. Azure has lots of resources such as AzureSQL, KeyVault, ResourceManagement etc.

    On my option, it is not make senses that use the authentication token (JWT) that can access all of the Azure Resources.

    Currently, we could get AzureCredentials from file, ServicePrincipalLoginInformation, UserLoginInformation

    If we want to operate a certain resource, then we could use authentication token (JWT) to do, take KeyVault as example.

        public static async Task GetAccessToken(string azureTenantId,string azureAppId,string azureSecretKey)
        {
    
            var context = new AuthenticationContext("https://login.windows.net/" + azureTenantId);
            ClientCredential clientCredential = new ClientCredential(azureAppId, azureSecretKey);
            var tokenResponse =await context.AcquireTokenAsync("https://vault.azure.net", clientCredential); //KeyVault resource : https://vault.azure.net
            var accessToken = tokenResponse.AccessToken;
            return accessToken;
        }
    
        var kv = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(GetAccessToken));
    

提交回复
热议问题