private bool RequestRedirectedToLogin(HttpContext context, bool bearerTokenReceived)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!string.IsNullOrWhiteSpace(context.User?.Identity?.Name))
            {
                return(false);
            }

            if (HandleUnauthorizedRequest(context))
            {
                return(true);
            }

            var querystring = string.Empty;

            foreach (var query in context.Request.Query)
            {
                if (!string.IsNullOrWhiteSpace(querystring))
                {
                    querystring += "&";
                }
                querystring += query.Key + "=" + query.Value;
            }
            string logonUri = context.Request.PathBase + context.Request.Path;

            if (!string.IsNullOrWhiteSpace(querystring))
            {
                logonUri += "?" + querystring;
            }

            var redirectLocation = _identityProviderClient.GetLoginUri(logonUri).ToString();

            context.Response.Redirect(redirectLocation);
            return(true);
        }
Exemplo n.º 2
0
        private bool RequestRedirectedToLogin(HttpContext context, bool bearerTokenReceived)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (!string.IsNullOrWhiteSpace(context.User?.Identity?.Name))
            {
                return(false);
            }

            if (HandleUnauthorizedRequest(context))
            {
                return(true);
            }

            var encodedUrl = context.Request.GetEncodedPathAndQuery();

            context.Response.Redirect(_identityProviderClient.GetLoginUri(encodedUrl).ToString());


            return(true);
        }