-
Notifications
You must be signed in to change notification settings - Fork 289
App Service Environment Detection for Production Mode #1011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
745322b
Add AppServicesAuthenticationInformation class
seantleonard 86d97a9
conditional startup in production for production appservice/swa app.
seantleonard ce4f23a
Merge branch 'main' into dev/seleonar/appServiceDetection
seantleonard a9b7dd6
updates to app service easyauth environment detection.
seantleonard c0b48cd
Add startup integration tests.
seantleonard d286235
Updated constant comments.
seantleonard 0ecb57a
Add correct spacing.
seantleonard b82da8f
add test category for CI/CD pipeline tests.
seantleonard eafcc84
Merge branch 'main' into dev/seleonar/appServiceDetection
Aniruddh25 9ebc1d5
Merge branch 'main' into dev/seleonar/appServiceDetection
Aniruddh25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Service/AuthenticationHelpers/AppServiceAuthenticationInformation.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using System; | ||
|
|
||
| namespace Azure.DataApiBuilder.Service.AuthenticationHelpers | ||
| { | ||
| /// <summary> | ||
| /// Info about the App Services configuration on the host. This class is an abridged mirror of | ||
| /// Microsoft.Identity.Web's AppServicesAuthenticationInformation.cs helper class used to | ||
| /// detect whether the app is running in an Azure App Service environment. | ||
| /// </summary> | ||
| /// <seealso cref="https://github.com/AzureAD/microsoft-identity-web/blob/master/src/Microsoft.Identity.Web/AppServicesAuth/AppServicesAuthenticationInformation.cs"/> | ||
| public static class AppServiceAuthenticationInfo | ||
| { | ||
| /// <summary> | ||
| /// Environment variable key whose value represents whether AppService EasyAuth is enabled ("true" or "false"). | ||
| /// </summary> | ||
| public const string APPSERVICESAUTH_ENABLED_ENVVAR = "WEBSITE_AUTH_ENABLED"; | ||
| /// <summary> | ||
| /// Environment variable key whose value represents Identity Provider such as "AzureActiveDirectory" | ||
| /// </summary> | ||
| public const string APPSERVICESAUTH_IDENTITYPROVIDER_ENVVAR = "WEBSITE_AUTH_DEFAULT_PROVIDER"; | ||
| /// <summary> | ||
| /// Error message used when AppService Authentication is configured in production mode in a non AppService Environment. | ||
| /// </summary> | ||
| public const string APPSERVICE_PROD_MISSING_ENV_CONFIG = "AppService environment not detected while runtime is in production mode."; | ||
| /// <summary> | ||
| /// Warning message logged when AppService environment not detected (applicable to development mode). | ||
| /// </summary> | ||
| public const string APPSERVICE_DEV_MISSING_ENV_CONFIG = "AppService environment not detected, EasyAuth authentication may not behave as expected."; | ||
|
|
||
| /// <summary> | ||
| /// Returns a best guess whether AppService is enabled in the environment by checking for | ||
| /// existence and value population of known AppService environment variables. | ||
| /// This check is determined to be "best guess" because environment variables could be | ||
| /// manually added or overridden. | ||
| /// This check's purpose is to help warn developers that an AppService environment is not detected | ||
| /// where the DataApiBuilder service is executing and DataApiBuilder is configured to use AppService | ||
| /// as the identity provider. | ||
| /// </summary> | ||
| public static bool AreExpectedAppServiceEnvVarsPresent() | ||
| { | ||
| string? appServiceEnabled = Environment.GetEnvironmentVariable(APPSERVICESAUTH_ENABLED_ENVVAR); | ||
| string? appServiceIdentityProvider = Environment.GetEnvironmentVariable(APPSERVICESAUTH_IDENTITYPROVIDER_ENVVAR); | ||
|
|
||
| if (string.IsNullOrEmpty(appServiceEnabled) || string.IsNullOrEmpty(appServiceIdentityProvider)) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return appServiceEnabled.Equals(value: "true", comparisonType: StringComparison.OrdinalIgnoreCase); | ||
| } | ||
| } | ||
| } | ||
4 changes: 2 additions & 2 deletions
4
src/Service/AuthenticationHelpers/EasyAuthAuthenticationDefaults.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.