Exemplo n.º 1
0
        internal static Task OnSigningIn(SigningInContext context)
        {
            if (context.Principal != null && context.SignInScheme == new IdentityCookieOptions().ExternalCookieAuthenticationScheme)
            {
                //This way we will know all events were fired.
                var identity         = context.Principal.Identities.First();
                var manageStoreClaim = identity?.Claims.Where(c => c.Type == "ManageStore" && c.Value == "false").FirstOrDefault();
                if (manageStoreClaim != null)
                {
                    identity.RemoveClaim(manageStoreClaim);
                    identity.AddClaim(new Claim("ManageStore", "Allowed"));
                }
            }

            return(Task.FromResult(0));
        }
Exemplo n.º 2
0
        public async Task <bool> InvokeReturnPathAsync()
        {
            log.LogDebug("InvokeReturnPathAsync called");

            var ticket = await HandleAuthenticateOnceAsync();

            if (ticket == null)
            {
                Logger.LogWarning("Invalid return state, unable to redirect.");
                Response.StatusCode = 500;
                return(true);
            }

            var context = new SigningInContext(Context, ticket)
            {
                SignInScheme = Options.SignInScheme,
                RedirectUri  = ticket.Properties.RedirectUri,
            };

            ticket.Properties.RedirectUri = null;

            await Options.Events.SigningIn(context);

            if (context.SignInScheme != null && context.Principal != null)
            {
                await Context.Authentication.SignInAsync(context.SignInScheme, context.Principal, context.Properties);
            }

            if (!context.IsRequestCompleted && context.RedirectUri != null)
            {
                if (context.Principal == null)
                {
                    // add a redirect hint that sign-in failed in some way
                    context.RedirectUri = QueryHelpers.AddQueryString(context.RedirectUri, "error", "access_denied");
                }
                Response.Redirect(context.RedirectUri);
                context.RequestCompleted();
            }

            return(context.IsRequestCompleted);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Invoked prior to the <see cref="System.Security.Claims.ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
 /// </summary>
 /// <param name="context"></param>
 /// <returns>A <see cref="Task"/> representing the completed operation.</returns>
 public virtual Task SigningIn(SigningInContext context) => OnSigningIn(context);
Exemplo n.º 4
0
 /// <summary>
 /// Invoked prior to the <see cref="ClaimsIdentity"/> being saved in a local cookie and the browser being redirected to the originally requested URL.
 /// </summary>
 /// <param name="context">Contains information about the login session as well as the user <see cref="ClaimsIdentity"/></param>
 /// <returns>A <see cref="Task"/> representing the completed operation.</returns>
 public virtual Task SigningIn(SigningInContext context) => OnSigningIn(context);