التكوين المستند إلى الملفات في مصادقة Azure App Service

باستخدام مصادقة خدمة التطبيق، يمكن تكوين إعدادات المصادقة باستخدام ملف. قد تحتاج إلى استخدام التكوين المستند إلى الملفات لاستخدام إمكانات معاينة معينة لمصادقة/تخويل خدمة التطبيقات قبل عرضها عبر واجهات برمجة تطبيقات Azure Resource Manager.

هام

تذكر أن حمولة التطبيق، وبالتالي هذا الملف، قد تنتقل بين البيئات، كما هو الحال مع الفتحات. من المحتمل أنك تريد تسجيل تطبيق مختلف مثبت على كل فتحة، وفي هذه الحالات، يجب أن تستمر في استخدام طريقة التكوين القياسية بدلا من استخدام ملف التكوين.

تمكين التكوين المستند إلى الملفات

  1. قم بإنشاء ملف JSON جديد للتكوين الخاص بك في جذر مشروعك (تم نشره على D:\home\site\wwwroot في تطبيق الويب / الوظيفة). املأ التكوين المطلوب وفقا لمرجع التكوين المستند إلى الملف. في حالة تعديل تكوين Azure Resource Manager موجود، تأكد من ترجمة الخصائص التي تم التقاطها في authsettings المجموعة إلى ملف التكوين الخاص بك.

  2. تعديل التكوين الموجود، الذي يتم التقاطه في واجهات برمجة تطبيقات Azure Resource Manager ضمن Microsoft.Web/sites/<siteName>/config/authsettingsV2. لتعديل هذا، يمكنك استخدام قالب Azure Resource Manager أو أداة مثل Azure Resource Explorer. ضمن مجموعة authsettingsV2 ، ستحتاج إلى تعيين خاصيتين (وقد تزيل خصائص أخرى):

    1. تعيين platform.enabled إلى "true"
    2. تعيين platform.configFilePath إلى اسم الملف (على سبيل المثال، "auth.json")

ملاحظة

يختلف تنسيق البرنامج platform.configFilePath بين الأنظمة الأساسية. على Windows ، يتم دعم كل من المسارات النسبية والمطلقة. ينصح قريب. بالنسبة لنظام التشغيل Linux ، يتم دعم المسارات المطلقة فقط حاليا ، لذلك يجب أن تكون قيمة الإعداد "/home/site/wwwroot/auth.json" أو ما شابه ذلك.

بمجرد إجراء تحديث التكوين هذا ، سيتم استخدام محتويات الملف لتحديد سلوك مصادقة / تفويض خدمة التطبيق لهذا الموقع. إذا كنت ترغب في العودة إلى تكوين Azure Resource Manager، فيمكنك القيام بذلك عن طريق إزالة تغيير الإعداد platform.configFilePath إلى فارغ.

مرجع ملف التكوين

يجب تخزين أي أسرار سيتم الرجوع إليها من ملف التكوين الخاص بك كإعدادات التطبيق. يمكنك تسمية الإعدادات بأي شيء تريده. فقط تأكد من أن المراجع من ملف التكوين تستخدم نفس المفاتيح.

يستنفد ما يلي خيارات التكوين الممكنة داخل الملف:

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

المزيد من الموارد