Filbaserad konfiguration i Azure App Service-autentisering

Med App Service autentisering kan autentiseringsinställningarna konfigureras med en fil. Du kan behöva använda filbaserad konfiguration för att använda vissa förhandsversionsfunktioner för App Service autentisering/auktorisering innan de exponeras via Azure Resource Manager API:er.

Viktigt

Kom ihåg att din appnyttolast, och därmed den här filen, kan flyttas mellan miljöer, som med platser. Det är troligt att du vill ha en annan appregistrering fäst på varje plats, och i dessa fall bör du fortsätta att använda standardkonfigurationsmetoden i stället för att använda konfigurationsfilen.

Aktivera filbaserad konfiguration

  1. Skapa en ny JSON-fil för konfigurationen i roten av projektet (distribuerad till D:\home\site\wwwroot i webb-/funktionsappen). Fyll i önskad konfiguration enligt den filbaserade konfigurationsreferensen. Om du ändrar en befintlig Azure-Resource Manager konfiguration ska du översätta de egenskaper som samlas in i authsettings samlingen till konfigurationsfilen.

  2. Ändra den befintliga konfigurationen, som samlas in i Azure Resource Manager-API:er under Microsoft.Web/sites/<siteName>/config/authsettingsV2. Om du vill ändra den kan du använda en Azure Resource Manager-mall eller ett verktyg som Azure Resource Explorer. I samlingen authsettingsV2 anger du två egenskaper (du kan ta bort andra):

    1. Ange platform.enabled till "true"
    2. Ange platform.configFilePath namnet på filen (till exempel "auth.json")

Anteckning

Formatet för platform.configFilePath varierar mellan plattformar. I Windows stöds både relativa och absoluta sökvägar. Relativ rekommenderas. För Linux stöds endast absoluta sökvägar för närvarande, så värdet för inställningen ska vara "/home/site/wwwroot/auth.json" eller liknande.

När du har gjort den här konfigurationsuppdateringen används innehållet i filen för att definiera beteendet för App Service autentisering/auktorisering för den platsen. Om du vill återgå till Azure Resource Manager konfiguration kan du göra det genom att ta bort ändringen av inställningen platform.configFilePath till null.

Referens för konfigurationsfil

Alla hemligheter som ska refereras från konfigurationsfilen måste lagras som programinställningar. Du kan namnge inställningarna vad du vill. Se bara till att referenserna från konfigurationsfilen använder samma nycklar.

Följande uttömmer möjliga konfigurationsalternativ i filen:

{
    "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"
                    ],
                }
            },
            //...
        }
    }
}

Fler resurser