我尝试通过我的.Net应用程序连接我的Azure Scheduler但是,在当前状态下,我得到了KeyNotFoundException: The given key was not present in the dictionary.
以上示例的问题是,我认为它基于以前版本的软件包。所以在最新版本中,我试图让它自己工作,但我无法做到。围绕此和AD Connect的文档数量非常有限,特别是在涉及新的Portal和最新版本时。我的代码示例如下,我不确定此时我做错了什么:
var tenantId = "{tenantId}"; // I have put objectId from Azure AD Properties
var clientId = "{clientId}"; // Here, I have created new App Registration in Azure AD and copied the AppId value
var subscriptionId = "{subscriptionId}"; //Subscription Id of the scheduler resource
UserLoginInformation loginInformation = new UserLoginInformation()
{
ClientId = clientId
};
ServiceClientCredentials serviceClientCredentials = new AzureCredentials(loginInformation, tenantId, AzureEnvironment.AzureGlobalCloud);
SchedulerManagementClient schedulerManagementClient =
new SchedulerManagementClient(serviceClientCredentials) { SubscriptionId = subscriptionId };
var schedulers = await schedulerManagementClient.JobCollections.GetWithHttpMessagesAsync("{resourceGroup}", "{jobCollectionName}");
答案 0 :(得分:0)
Tennat Id 不应用 objectid 。我们可以从Azure门户获取它,更多细节请参考屏幕截图。
如果用户不需要多因素身份验证。请尝试使用以下代码。
var tenantId = "tenantId"; // Not the object id, it is Azure directory Id
var clientId = "client Id"; // Here, I have created new App Registration in Azure AD and copied the AppId value
var subscriptionId = "subscription Id"; //Subscription Id of the scheduler resource
var resourceGroup = "resource group";
var jobCollectionName = "job name";
UserLoginInformation loginInformation = new UserLoginInformation()
{
ClientId = clientId,
UserName = "xxx@example.com",
Password = "xxxxxx"
};
ServiceClientCredentials serviceClientCredentials = new AzureCredentials(loginInformation, tenantId, AzureEnvironment.AzureGlobalCloud);
SchedulerManagementClient schedulerManagementClient =
new SchedulerManagementClient(serviceClientCredentials) { SubscriptionId = subscriptionId };
var schedulers = await schedulerManagementClient.JobCollections.GetWithHttpMessagesAsync($"{resourceGroup}", $"{jobCollectionName}");