2016-07-14 42 views
2

爲了實現我們的構建過程的自動化,我在尋找通過Powershell腳本更改現有Active Directory應用程序的「回覆URL」的可能性。通過Powershell命令更改Azure Active Directory「回覆URL」

官方documentation只是描述了一種方式,如何在Web門戶的幫助下進行更改。

關於此主題已有Github issue。但也許有人在過去遇到類似的問題並解決了它?

+0

我通過使用nuget包'Microsoft.Azure.ActiveDirectory.GraphClient'得到了類似這樣的工作,但我並沒有直接在Powershell中完成它,而是使用C#構建了一個小型控制檯程序,然後通過Powershell腳本調用它。如果您願意,我可以爲您提供更多關於如何以這種方式完成的詳細信息。 –

+0

感謝您的回覆,@TomWuyts。我真的很感謝您的一些細節。 – ErBeEn

回答

3

作爲一種替代方法,您可以將以下腳本放在控制檯應用程序中,然後從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/,您的新回覆網址。

(小發明,我已經從我現有的代碼報廢上面的代碼放在一起,我想我已經複製了所有必需的真實的東西,但我沒有測試上述結果。)

5

隨着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 
}