Skip to content

Commit

Permalink
Fixes Logout error when using Easy Auth v2 (#1246)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmprieur authored Jun 7, 2021
1 parent a4ef0d3 commit e435bbb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class AppServicesAuthenticationInformation
internal const string AppServicesAuthIdentityProviderEnvironmentVariable = "WEBSITE_AUTH_DEFAULT_PROVIDER"; // AzureActiveDirectory
internal const string AppServicesAuthAzureActiveDirectory = "AzureActiveDirectory";
internal const string AppServicesAuthIdTokenHeader = "X-MS-TOKEN-AAD-ID-TOKEN";
internal const string AppServicesWebSiteAuthApiPrefix = "WEBSITE_AUTH_API_PREFIX";
private const string AppServicesAuthIdpTokenHeader = "X-MS-CLIENT-PRINCIPAL-IDP";

// Artificially added by Microsoft.Identity.Web to help debugging App Services. See the Debug controller of the test app
Expand Down Expand Up @@ -57,7 +58,22 @@ public static string? LogoutUrl
{
get
{
return Environment.GetEnvironmentVariable(AppServicesAuthLogoutPathEnvironmentVariable);
// Try $AppServicesAuthLogoutPathEnvironmentVariable (AppServices auth v1.0)
string? logoutPath = Environment.GetEnvironmentVariable(AppServicesAuthLogoutPathEnvironmentVariable);
if (!string.IsNullOrEmpty(logoutPath))
{
return logoutPath;
}

// Try the $(AppServicesWebSiteAuthApiPrefix)
string? webSite = Environment.GetEnvironmentVariable(AppServicesWebSiteAuthApiPrefix);
if (!string.IsNullOrEmpty(webSite))
{
return $"{webSite}/logout";
}

// Fallback
return "/.auth/logout";
}
}

Expand Down
1 change: 1 addition & 0 deletions tests/Microsoft.Identity.Web.Test/WebAppExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private void ResetAppServiceEnv()
Environment.SetEnvironmentVariable(AppServicesAuthenticationInformation.AppServicesAuthClientIdEnvironmentVariable, string.Empty);
Environment.SetEnvironmentVariable(AppServicesAuthenticationInformation.AppServicesAuthClientSecretEnvironmentVariable, string.Empty);
Environment.SetEnvironmentVariable(AppServicesAuthenticationInformation.AppServicesAuthLogoutPathEnvironmentVariable, string.Empty);
Environment.SetEnvironmentVariable(AppServicesAuthenticationInformation.AppServicesWebSiteAuthApiPrefix, string.Empty);
Environment.SetEnvironmentVariable(AppServicesAuthenticationInformation.AppServicesAuthIdentityProviderEnvironmentVariable, string.Empty);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/WebAppCallsMicrosoftGraph/Pages/Debugging.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
@{
string[] importantEnvironmentVariables = new string[] {
"WEBSITE_AUTH_ENABLED", "WEBSITE_AUTH_OPENID_ISSUER", "WEBSITE_AUTH_CLIENT_ID",
"WEBSITE_AUTH_CLIENT_SECRET", "WEBSITE_AUTH_LOGOUT_PATH", "WEBSITE_AUTH_DEFAULT_PROVIDER"};
"WEBSITE_AUTH_CLIENT_SECRET", "WEBSITE_AUTH_LOGOUT_PATH", "WEBSITE_AUTH_DEFAULT_PROVIDER",
"WEBSITE_AUTH_API_PREFIX"
};

string[] importantHeaders = new string[] { "X-MS-TOKEN-AAD-ID-TOKEN", "X-MS-CLIENT-PRINCIPAL-IDP", "X-MS-TOKEN-AAD-ACCESS-TOKEN" };
}
Expand Down

0 comments on commit e435bbb

Please sign in to comment.