Konfigurasi berbasis file di autentikasi Azure App Service

Dengan Autentikasi App Service, pengaturan autentikasi dapat dikonfigurasi dengan file. Anda mungkin perlu menggunakan konfigurasi berbasis file untuk menggunakan kemampuan pratinjau tertentu dari autentikasi/otorisasi App Service sebelum diekspos melalui AZURE Resource Manager API.

Penting

Ingat bahwa muatan aplikasi Anda, dan karena itu file ini, dapat berpindah antar lingkungan, seperti halnya slot. Kemungkinan Anda ingin pendaftaran aplikasi yang berbeda disematkan ke setiap slot, dan dalam kasus ini, Anda harus terus menggunakan metode konfigurasi standar alih-alih menggunakan file konfigurasi.

Mengaktifkan konfigurasi berbasis file

  1. Buat file JSON baru untuk konfigurasi Anda di root proyek Anda (disebarkan ke D:\home\site\wwwroot di aplikasi web / fungsi Anda). Isi konfigurasi yang Anda inginkan sesuai dengan referensi konfigurasi berbasis file. Jika memodifikasi konfigurasi Azure Resource Manager yang sudah ada, pastikan untuk menerjemahkan properti yang diambil dalam koleksi authsettings ke dalam file konfigurasi Anda.

  2. Ubah konfigurasi yang sudah ada, yang diambil di API Azure Resource Manager di bawah Microsoft.Web/sites/<siteName>/config/authsettingsV2. Untuk memodifikasinya, Anda dapat menggunakan templat Azure Resource Manager atau alat seperti Azure Resource Explorer. Dalam koleksi authsettingsV2, atur dua properti (Anda dapat menghapus yang lain):

    1. Atur platform.enabled ke “true”
    2. Atur platform.configFilePath ke nama file (misalnya, "auth.json")

Catatan

Format untuk platform.configFilePath bervariasi di antara platform. Pada Windows, jalur relatif dan absolut didukung. Relatif disarankan. Untuk Linux, hanya jalur absolut yang didukung saat ini, sehingga nilai pengaturan harus "/home/site/wwwroot/auth.json" atau yang serupa.

Setelah Anda membuat pembaruan konfigurasi ini, konten file akan digunakan untuk menentukan perilaku Autentikasi / Otorisasi App Service untuk situs tersebut. Jika Anda ingin kembali ke konfigurasi Azure Resource Manager, Anda dapat melakukannya dengan menghapus perubahan pengaturan platform.configFilePath ke null.

Referensi file konfigurasi

Setiap rahasia yang akan direferensikan dari file konfigurasi Anda harus disimpan sebagai pengaturan aplikasi. Anda dapat menamai pengaturan apa pun yang Anda inginkan. Pastikan bahwa referensi dari file konfigurasi menggunakan kunci yang sama.

Berikut ini menghabiskan kemungkinan opsi konfigurasi dalam file:

{
    "platform": {
        "enabled": <true|false>
    },
    "globalValidation": {
        "unauthenticatedClientAction": "RedirectToLoginPage|AllowAnonymous|RejectWith401|RejectWith404",
        "redirectToProvider": "<default provider alias>",
        "excludedPaths": [
            "/path1",
            "/path2",
            "/path3/subpath/*"
        ]
    },
    "httpSettings": {
        "requireHttps": <true|false>,
        "routes": {
            "apiPrefix": "<api prefix>"
        },
        "forwardProxy": {
            "convention": "NoProxy|Standard|Custom",
            "customHostHeaderName": "<host header value>",
            "customProtoHeaderName": "<proto header value>"
        }
    },
    "login": {
        "routes": {
            "logoutEndpoint": "<logout endpoint>"
        },
        "tokenStore": {
            "enabled": <true|false>,
            "tokenRefreshExtensionHours": "<double>",
            "fileSystem": {
                "directory": "<directory to store the tokens in if using a file system token store (default)>"
            },
            "azureBlobStorage": {
                "sasUrlSettingName": "<app setting name containing the sas url for the Azure Blob Storage if opting to use that for a token store>"
            }
        },
        "preserveUrlFragmentsForLogins": <true|false>,
        "allowedExternalRedirectUrls": [
            "https://uri1.azurewebsites.net/",
            "https://uri2.azurewebsites.net/",
            "url_scheme_of_your_app://easyauth.callback"
        ],
        "cookieExpiration": {
            "convention": "FixedTime|IdentityDerived",
            "timeToExpiration": "<timespan>"
        },
        "nonce": {
            "validateNonce": <true|false>,
            "nonceExpirationInterval": "<timespan>"
        }
    },
    "identityProviders": {
        "azureActiveDirectory": {
            "enabled": <true|false>,
            "registration": {
                "openIdIssuer": "<issuer url>",
                "clientId": "<app id>",
                "clientSecretSettingName": "APP_SETTING_CONTAINING_AAD_SECRET",
            },
            "login": {
                "loginParameters": [
                    "paramName1=value1",
                    "paramName2=value2"
                ]
            },
            "validation": {
                "allowedAudiences": [
                    "audience1",
                    "audience2"
                ]
            }
        },
        "facebook": {
            "enabled": <true|false>,
            "registration": {
                "appId": "<app id>",
                "appSecretSettingName": "APP_SETTING_CONTAINING_FACEBOOK_SECRET"
            },
            "graphApiVersion": "v3.3",
            "login": {
                "scopes": [
                    "public_profile",
                    "email"
                ]
            },
        },
        "gitHub": {
            "enabled": <true|false>,
            "registration": {
                "clientId": "<client id>",
                "clientSecretSettingName": "APP_SETTING_CONTAINING_GITHUB_SECRET"
            },
            "login": {
                "scopes": [
                    "profile",
                    "email"
                ]
            }
        },
        "google": {
            "enabled": true,
            "registration": {
                "clientId": "<client id>",
                "clientSecretSettingName": "APP_SETTING_CONTAINING_GOOGLE_SECRET"
            },
            "login": {
                "scopes": [
                    "profile",
                    "email"
                ]
            },
            "validation": {
                "allowedAudiences": [
                    "audience1",
                    "audience2"
                ]
            }
        },
        "twitter": {
            "enabled": <true|false>,
            "registration": {
                "consumerKey": "<consumer key>",
                "consumerSecretSettingName": "APP_SETTING_CONTAINING TWITTER_CONSUMER_SECRET"
            }
        },
        "apple": {
            "enabled": <true|false>,
            "registration": {
                "clientId": "<client id>",
                "clientSecretSettingName": "APP_SETTING_CONTAINING_APPLE_SECRET"
            },
            "login": {
                "scopes": [
                    "profile",
                    "email"
                ]
            }
        },
        "openIdConnectProviders": {
            "<providerName>": {
                "enabled": <true|false>,
                "registration": {
                    "clientId": "<client id>",
                    "clientCredential": {
                        "clientSecretSettingName": "<name of app setting containing client secret>"
                    },
                    "openIdConnectConfiguration": {
                        "authorizationEndpoint": "<url specifying authorization endpoint>",
                        "tokenEndpoint": "<url specifying token endpoint>",
                        "issuer": "<url specifying issuer>",
                        "certificationUri": "<url specifying jwks endpoint>",
                        "wellKnownOpenIdConfiguration": "<url specifying .well-known/open-id-configuration endpoint - if this property is set, the other properties of this object are ignored, and authorizationEndpoint, tokenEndpoint, issuer, and certificationUri are set to the corresponding values listed at this endpoint>"
                    }
                },
                "login": {
                    "nameClaimType": "<name of claim containing name>",
                    "scopes": [
                        "openid",
                        "profile",
                        "email"
                    ],
                    "loginParameterNames": [
                        "paramName1=value1",
                        "paramName2=value2"
                    ],
                }
            },
            //...
        }
    }
}

Sumber daya lainnya