protected override void OnAfterCreateLoginOAuth20Headers(IDictionary <string, string> headers)
        {
            if (headers != null)
            {
                headers["resource"]      = AzureDirectoryAppId;
                headers["nonce"]         = BuildNonce();
                headers["response_mode"] = "query";
                if (LoginOptions.HasFlag(AuthLoginOptions.RegisterApplication))
                {
                    headers["prompt"] = "admin_consent";
                }
            }

            base.OnAfterCreateLoginOAuth20Headers(headers);
        }
        private string GetRedirectUri()
        {
            string absoluteApplicationPath = GetAbsoluteApplicationPath();

            if (string.IsNullOrEmpty(absoluteApplicationPath) || absoluteApplicationPath[absoluteApplicationPath.Length - 1] != '/')
            {
                absoluteApplicationPath += "/";
            }

            string redirectUri = absoluteApplicationPath + RequestCallback;

            var uriBuilder = new UriBuilder(redirectUri);

            if (UserLocationStorageType == UserLocationStorageType.RedirectUri)
            {
                var queryStringValues = Extensions.ParseQueryString(uriBuilder.Query);
                queryStringValues[ProviderParameter] = Name;
                queryStringValues[OptionsParameter]  = LoginOptions.ToString("D");

                if (MaintainUserLocation)
                {
                    string returnUrl = HttpContext.Current.Request.RawUrl;
                    if (!LoginOptions.HasFlag(AuthLoginOptions.StayOnCurrentPage) || !IsUrlLocalToHost(returnUrl))
                    {
                        returnUrl = HttpContext.Current.Request.QueryString[UrlParameter];
                    }
                    if (!IsUrlLocalToHost(returnUrl))
                    {
                        returnUrl = HttpContext.Current.Request.QueryString[ReturnUrlParameter];
                    }
                    if (!IsUrlLocalToHost(returnUrl))
                    {
                        returnUrl = SuccessUrl;
                    }

                    queryStringValues[UrlParameter] = returnUrl;
                }

                uriBuilder.Query = Extensions.BuildQueryString(queryStringValues);
            }

            return(uriBuilder.Uri.AbsoluteUri);
        }