Using authentication token in azure sdk fluent

前端 未结 3 1732
别那么骄傲
别那么骄傲 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:05

    Starting from Azure Management Fluent SDK v1.10 you can use any credentials provider that is derived from ServiceClientCredentials. In other words you should be able to pass already acquired Bearer token string to AzureCredentials constructor like this

    var customTokenProvider = new AzureCredentials(
                            new TokenCredentials(armAuthToken),
                            new TokenCredentials(graphAuthToken),
                            tenantId,
                            AzureEnvironment.AzureGlobalCloud);
    
    var client = RestClient
                        .Configure()
                        .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                        .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                        .WithCredentials(customTokenProvider)
                        .Build();
    
    var authenticatedClient = Azure.Authenticate(client, tenantId);
    

提交回复
热议问题