コード例 #1
0
        public virtual async Task <IActionResult> SignOut(SignOutForm form)
        {
            var authenticationSchemeName = this.User.Claims.FindFirstIdentityProviderClaim()?.Value;

            if (this.User.Identity.IsAuthenticated)
            {
                await this.HttpContext.SignOutAsync();
            }

            // ReSharper disable InvertIf
            if (authenticationSchemeName != null)
            {
                var authenticationScheme = await this.AuthenticationSchemeLoader.GetAsync(authenticationSchemeName);

                if (authenticationScheme != null && authenticationScheme.SignOutSupport)
                {
                    var url = this.Url.Action(nameof(this.SignOut), new { signOutId = form?.Id });

                    return(SignOut(new AuthenticationProperties {
                        RedirectUri = url
                    }, authenticationSchemeName));
                }
            }
            // ReSharper restore InvertIf

            return(this.View("SignedOut"));
        }
コード例 #2
0
        public virtual async Task <IActionResult> SignOut(SignOutForm form)
        {
            if (this.User.Identity.IsAuthenticated)
            {
                await this.HttpContext.SignOutAsync();
            }

            return(this.View("SignedOut"));
        }
コード例 #3
0
        public async Task <ActionResult> SignOut(SignOutForm form)
        {
            try
            {
                await _service.SignOut(form.Id, form.Token);

                return(Ok());
            }
            catch (Exception e)
            {
                return(StatusCode(215, e.Message));
            }
        }
        public virtual async Task <IActionResult> SignOut(SignOutForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            form.ReturnUrl = this.ResolveAndValidateReturnUrl(form.ReturnUrl);

            if (this.User?.Identity != null && this.User.Identity.IsAuthenticated)
            {
                await this.HttpContext.SignOutAsync(AuthenticationSchemes.Cookie);
            }

            return(this.Redirect(form.ReturnUrl));
        }
コード例 #5
0
        public virtual async Task <IActionResult> SignOut(SignOutForm form)
        {
            if (form == null)
            {
                throw new ArgumentNullException(nameof(form));
            }

            var model = await this.CreateSignedOutViewModelAsync(form.Id);

            string externalSignOutScheme = null;

            if (this.User.Identity.IsAuthenticated)
            {
                var authenticationSchemeName = this.User.Claims.FindFirstIdentityProviderClaim()?.Value;

                if (authenticationSchemeName != null && !string.Equals(authenticationSchemeName, Duende.IdentityServer.IdentityServerConstants.LocalIdentityProvider, StringComparison.OrdinalIgnoreCase))
                {
                    var authenticationScheme = await this.Facade.AuthenticationSchemeRetriever.GetAsync(authenticationSchemeName);

                    if (authenticationScheme != null && authenticationScheme.SignOutSupport)
                    {
                        externalSignOutScheme = authenticationSchemeName;
                        form.Id ??= await this.Facade.Interaction.CreateLogoutContextAsync();
                    }
                }

                await this.Facade.Identity.SignOutAsync();

                await this.Facade.Events.RaiseAsync(new UserLogoutSuccessEvent(this.User.GetSubjectId(), this.User.GetDisplayName()));
            }

            // ReSharper disable InvertIf
            if (externalSignOutScheme != null)
            {
                var redirectUrl = this.Url.Action("SignOut", new { signOutId = form.Id });

                return(this.SignOut(new AuthenticationProperties {
                    RedirectUri = redirectUrl
                }, externalSignOutScheme));
            }
            // ReSharper restore InvertIf

            this.HttpContext.SetSignedOut();

            return(this.View("SignedOut", model));
        }