protected virtual async Task <HandleRequestResult> HandleAccessDeniedErrorAsync(AuthenticationProperties properties)
        {
            Logger.AccessDeniedError();
            var context = new AccessDeniedContext(Context, Scheme, Options)
            {
                AccessDeniedPath   = Options.AccessDeniedPath,
                Properties         = properties,
                ReturnUrl          = properties?.RedirectUri,
                ReturnUrlParameter = Options.ReturnUrlParameter
            };
            await Events.AccessDenied(context);

            if (context.Result != null)
            {
                if (context.Result.Handled)
                {
                    Logger.AccessDeniedContextHandled();
                }
                else if (context.Result.Skipped)
                {
                    Logger.AccessDeniedContextSkipped();
                }

                return(context.Result);
            }

            // If an access denied endpoint was specified, redirect the user agent.
            // Otherwise, invoke the RemoteFailure event for further processing.
            if (context.AccessDeniedPath.HasValue)
            {
                string uri = context.AccessDeniedPath;
                if (!string.IsNullOrEmpty(context.ReturnUrlParameter) && !string.IsNullOrEmpty(context.ReturnUrl))
                {
                    uri = QueryHelpers.AddQueryString(uri, context.ReturnUrlParameter, context.ReturnUrl);
                }
                Response.Redirect(uri);

                return(HandleRequestResult.Handle());
            }

            return(HandleRequestResult.Fail("Access was denied by the resource owner or by the remote server.", properties));
        }
 /// <summary>
 /// Discontinue processing the request in the current handler.
 /// </summary>
 public void SkipHandler() => Result = HandleRequestResult.SkipHandler();
 /// <summary>
 /// Discontinue all processing for this request and return to the client.
 /// The caller is responsible for generating the full response.
 /// </summary>
 public void HandleResponse() => Result = HandleRequestResult.Handle();
Exemple #4
0
 public void Fail(string failureMessage) => Result = HandleRequestResult.Fail(failureMessage);
Exemple #5
0
 public void Fail(Exception failure) => Result = HandleRequestResult.Fail(failure);
Exemple #6
0
 /// <summary>
 /// Calls success creating a ticket with the <see cref="Principal"/> and <see cref="Properties"/>.
 /// </summary>
 public void Success() => Result = HandleRequestResult.Success(new AuthenticationTicket(Principal, Properties, Scheme.Name));