0

I have a Server-Side Blazor app that I am developing. I have it linked up to Azure AD and authenticating. This all works fine using Microsoft.AspNetCore.Authentication.AzureAD.UI. From what I can tell the SignOut feature is just a navigation path that leads to the AzureAD area in the WebAPI of the assembly. Any ideas on how to implement this?

Aaron Rumford
  • 556
  • 1
  • 7
  • 21

1 Answers1

1

Try this:

            var domain = HttpContextAccessor.HttpContext.Request.Host.ToUriComponent();
            var redirectUrl = HttpUtility.UrlEncode($"{HttpContextAccessor.HttpContext.Request.Scheme}://{domain}/Index");
    HttpContextAccessor.HttpContext.Response.Redirect($"https://login.microsoftonline.com/{domain}/oauth2/logout?post_logout_redirect_uri={redirectUrl}");
auburg
  • 1,373
  • 2
  • 12
  • 22
  • Is there a way to do it from inside a Blazor page? – Aaron Rumford Feb 07 '20 at 16:10
  • Nevermind. I figured it out. ```protected override void OnInitialized() { var domain = Http.HttpContext.Request.Host.ToUriComponent(); var redirect = HttpUtility.UrlEncode(""); Nav.NavigateTo($"https://login.microsoftonline.com/{domain}/oauth2/logout?post_logout_redirect_uri={redirect}"); } – Aaron Rumford Feb 07 '20 at 16:21
  • 1
    Refer to this: https://stackoverflow.com/questions/53817373/how-do-i-access-httpcontext-in-server-side-blazor in order to access HttpContextAccessor from your server side blazer page. I've edited my answer accordingly. – auburg Feb 07 '20 at 16:21