为了实现我们的构建过程的自动化,我在寻找通过Powershell脚本更改现有Active Directory应用程序的“回复URL”的可能性。通过Powershell命令更改Azure Active Directory“回复URL”
官方documentation只是描述了一种方式,如何在Web门户的帮助下进行更改。
关于此主题已有Github issue。但也许有人在过去遇到类似的问题并解决了它?
为了实现我们的构建过程的自动化,我在寻找通过Powershell脚本更改现有Active Directory应用程序的“回复URL”的可能性。通过Powershell命令更改Azure Active Directory“回复URL”
官方documentation只是描述了一种方式,如何在Web门户的帮助下进行更改。
关于此主题已有Github issue。但也许有人在过去遇到类似的问题并解决了它?
作为一种替代方法,您可以将以下脚本放在控制台应用程序中,然后从Powershell脚本中调用该程序。首先,包括nuget包Microsoft.Azure.ActiveDirectory.GraphClient
。
//First, log in into Azure:
Uri servicePointUri = new Uri("https://graph.windows.net");
Uri serviceRoot = new Uri(servicePointUri, "YourTenantId");
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(serviceRoot,
async() => await AcquireTokenAsyncForUser("YourTenant.onmicrosoft.com", "ClientIdForThisApplication"));
//A popup will now be shown to you, requiring you to log in into the AAD.
//Find your application
var existingApp = activeDirectoryClient.Applications.Where(s => s.DisplayName == "NameOfYourApplication").Take(1).ExecuteAsync().Result;
if (existingApp != null && existingApp.CurrentPage != null && existingApp.CurrentPage.Count == 1)
{
//Application found
var app = existingApp.CurrentPage.First();
//Change the Reply Url
app.ReplyUrls.Clear();
app.ReplyUrls.Add("http://YourNewReplyUrl/");
app.UpdateAsync().Wait();
}
你将需要改变的东西多一点细节:
YourTenantId
,这是这是我们用来识别您的天蓝色的Active Directory(AAD)的GUID。YourTenant.onmicrosoft.com
,基本上这是你的AAD后跟“.onmicrosoft.com”的名称。ClientIdForThisApplication
,您将不得不手动在应用程序下的AAD中添加上述控制台应用程序。 (作为Native Client应用程序)。在配置选项卡中,您可以找到该应用程序的客户端ID。这只需要做一次,你可以继续使用这个应用程序(和它的客户端ID)为你所有的构建。NameOfYourApplication
,您希望更改的应用程序的名称,因为它在您的AAD中已知。http://YourNewReplyUrl/
,您的新回复网址。(小发明,我已经从我现有的代码报废上面的代码放在一起,我想我已经复制了所有必需的真实的东西,但我没有测试上述结果。)
随着Active Directory Powershell Module这更简单。 您首先需要安装的模块,像这样:
Install-Module -Name AzureAD
然后您需要登录到Azure的AD。这可以交互式完成,如果你在桌面上,使用Connect-AzureAD
,它会弹出一个要求你登录的弹出窗口。在CI环境中,您可以使用服务主体进行身份验证。
当鉴定,下面将做的工作(记得要改变Azure的AD应用ID(这是一个你通常得到来自MS的错误信息说Reply URL <bladibla> is not valid for application <guid>
和答复网址:
$appId = "9e5675c3-7cd5-47c1-9d21-72204cd1fe2f" #Remember to change
$newReplyUrl = "https://mywebapp.azurewebsites.net/SignIn/"; #Remember to change
# Get Azure AD App
$app = Get-AzureADApplication -Filter "AppId eq '$($appId)'"
$replyUrls = $app.ReplyUrls;
# Add Reply URL if not already in the list
if ($replyUrls -NotContains $newReplyUrl) {
$replyUrls.Add($newReplyUrl)
Set-AzureADApplication -ObjectId $app.ObjectId -ReplyUrls $replyUrls
}
我通过使用nuget包'Microsoft.Azure.ActiveDirectory.GraphClient'得到了类似这样的工作,但我并没有直接在Powershell中完成它,而是使用C#构建了一个小型控制台程序,然后通过Powershell脚本调用它。如果您愿意,我可以为您提供更多关于如何以这种方式完成的详细信息。 –
感谢您的回复,@TomWuyts。我真的很感谢您的一些细节。 – ErBeEn