2016-03-07 16 views
8

Dịch vụ ứng dụng Azure bao gồm giải pháp xác thực chìa khóa trao tay, trong lưỡi thiết lập Xác thực/ủy quyền. Điều này cho phép tôi cấu hình xác thực Active Directory cho api web dịch vụ ứng dụng của tôi. Tôi có một kịch bản cung cấp để thiết lập môi trường của mình và tôi muốn tự động hóa cấu hình Xác thực dịch vụ ứng dụng, hoặc thông qua một mẫu ARM hoặc thông qua các lệnh Powershell.Có thể viết cấu hình Xác thực dịch vụ ứng dụng Azure không?

Tôi đã thử sử dụng resource.azure.com để xem thiết lập trang web của mình nhưng tôi không thể thấy cấu hình liên quan đến AD. Tôi đã thử tìm kiếm các mẫu ARM thực hiện việc này, không thành công. Tôi cũng không thể nhìn thấy một lệnh quản lý tài nguyên Azure có thể làm điều này.

Có ai biết cách tự động hóa cấu hình Xác thực dịch vụ ứng dụng, cụ thể cho xác thực AD không?

Trả lời

6

Tôi có thể tự mình trả lời: điều này thực sự có thể được viết thông qua mẫu ARM. (Ban đầu tôi đã thử sử dụng resources.azure.com nhưng nó đã không hiển thị tất cả các thông tin cấu hình cho trang web của tôi; đăng xuất và trở lại trong một lần nữa làm cho nó hoạt động.) Giải pháp là sử dụng một tài nguyên lồng nhau trong tài nguyên Microsoft.Web/sites cho ứng dụng web của bạn loại config và tên web để xác định các cài đặt, ví dụ:

{ 
    "type": "Microsoft.Web/sites", 
    ... 
    "resources": [ 
    { 
     "apiVersion": "2015-04-01", 
     "name": "web", 
     "type": "config", 
     "dependsOn": [ 
     "[resourceId('Microsoft.Web/sites', parameters('someName'))]" 
     ], 
     "properties": { 
     "siteAuthEnabled": true, 
     "siteAuthSettings": { 
      "enabled": null, 
      "httpApiPrefixPath": null, 
      "unauthenticatedClientAction": null, 
      "tokenStoreEnabled": null, 
      "allowedExternalRedirectUrls": null, 
      "defaultProvider": null, 
      "clientId": "REMOVED", 
      "clientSecret": null, 
      "issuer": "https://sts.windows.net/REMOVED/", 
      "allowedAudiences": null, 
      "additionalLoginParams": null, 
      "isAadAutoProvisioned": false, 
      "aadClientId": "REMOVED", 
      "openIdIssuer": "https://sts.windows.net/REMOVED/", 
      "googleClientId": null, 
      "googleClientSecret": null, 
      "googleOAuthScopes": null, 
      "facebookAppId": null, 
      "facebookAppSecret": null, 
      "facebookOAuthScopes": null, 
      "twitterConsumerKey": null, 
      "twitterConsumerSecret": null, 
      "microsoftAccountClientId": null, 
      "microsoftAccountClientSecret": null, 
      "microsoftAccountOAuthScopes": null 
     } 
     } 
    } 
    ] 
} 
2

Dưới đây là một cách để làm điều đó bằng lệnh Powershell thẳng.

Trước tiên, bạn có thể xem các thiết lập auth hiện tại sử dụng:

$rgName = "ResourceGroupName" 
$resourceType = "Microsoft.Web/sites/config" 
$resourceName = "service-name/authsettings" 

$resource = Invoke-AzureRmResourceAction -ResourceGroupName $rgName ` 
-ResourceType $resourceType -ResourceName $resourcename -Action list ` 
-ApiVersion 2015-08-01 -Force 

$resource.Properties 

Sau đó, bạn có thể mất các giá trị của những tài sản và sử dụng chúng để thiết lập các PropertyObject (các thuộc tính hiển thị dưới đây liên quan đến thẩm định AAD, sử dụng một dịch vụ chính):

$PropertiesObject = @{ 
    "enabled" = "True"; 
    "unauthenticatedClientAction" = "0"; 
    "defaultProvider" = "0"; 
    "tokenStoreEnabled" = "True"; 
    "clientId" = "<your client ID here>"; 
    "issuer" = "https://sts.windows.net/<your AAD ID here>/"; 
    "allowedAudiences" = "{https://<service name>.azurewebsites.net}"; 
    "isAadAutoProvisioned" = "True"; 
    "aadClientId" = "<your client ID here>"; 
    "openIdIssuer" = "https://sts.windows.net/<your AAD ID here>/"; 
} 

New-AzureRmResource -PropertyObject $PropertiesObject ` 
-ResourceGroupName $rgName -ResourceType $resourceType ` 
-ResourceName $resourcename -ApiVersion 2015-08-01 -Force 

Tôi thấy dễ dàng hơn để bật xác thực trong cổng, xem thuộc tính, sau đó sử dụng các giá trị đó để đặt PropertyObject.

1

Đây là bây giờ merged into Azure CLI và có sẵn theo az webapp auth.

Azure CLI Ref Page:

az webapp auth update --name 
         --resource-group 
         [--aad-allowed-token-audiences] 
         [--aad-client-id] 
         [--aad-client-secret] 
         [--aad-token-issuer-url] 
         [--action {AllowAnonymous, LoginWithAzureActiveDirectory, LoginWithFacebook, LoginWithGoogle, LoginWithMicrosoftAccount, LoginWithTwitter}] 
         [--allowed-external-redirect-urls] 
         [--enabled {false, true}] 
         [--facebook-app-id] 
         [--facebook-app-secret] 
         [--facebook-oauth-scopes] 
         [--google-client-id] 
         [--google-client-secret] 
         [--google-oauth-scopes] 
         [--microsoft-account-client-id] 
         [--microsoft-account-client-secret] 
         [--microsoft-account-oauth-scopes] 
         [--runtime-version] 
         [--slot] 
         [--token-refresh-extension-hours] 
         [--token-store {false, true}] 
         [--twitter-consumer-key] 
         [--twitter-consumer-secret] 
Các vấn đề liên quan