使用现有令牌调用Microsoft.Azure.Fluent API

问题描述 投票:0回答:1

我正在使用Microsoft.Azure…Fluent程序包对Azure进行REST API调用。当前,我正在使用以下内容初始化IAzure对象:

            var Credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
                appID,
                secret,
                tenantID,
                AzureEnvironment.AzureGlobalCloud);

            Azure = Microsoft.Azure.Management.Fluent.Azure
                .Configure()
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                .Authenticate(Credentials)
                .WithSubscription(subscriptionID);

是否有可能使用现有的“代表”令牌而不是使用客户端ID,客户端密钥来初始化Azure对象?

azure token fluent
1个回答
0
投票

前端Web应用程序既可以获取图形令牌也可以获取ARM令牌,因此我可以使其按如下方式工作:

            var customTokenProvider = new AzureCredentials(
                                    new TokenCredentials(**armToken**),
                                    new TokenCredentials(**graphToken**),
                                    tenantID,
                                    AzureEnvironment.AzureGlobalCloud);

            Azure = Microsoft.Azure.Management.Fluent.Azure
                .Configure()
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                .Authenticate(customTokenProvider)
                .WithSubscription(subscriptionID);
© www.soinside.com 2019 - 2024. All rights reserved.