Exemplo n.º 1
0
        public async Task <IHttpActionResult> Logout(string id = null)
        {
            Logger.Info("Logout endpoint submitted");

            if (id != null && id.Length > MaxSignInMessageLength)
            {
                Logger.Error("id param is longer than allowed length");
                return(RenderErrorPage());
            }

            var user = (ClaimsPrincipal)User;

            if (user != null && user.Identity.IsAuthenticated)
            {
                var sub = user.GetSubjectId();
                Logger.InfoFormat("Logout requested for subject: {0}", sub);
            }

            Logger.Info("Clearing cookies");
            context.QueueRemovalOfSignOutMessageCookie(id);
            context.ClearAuthenticationCookies();
            context.SignOutOfExternalIdP(id);

            string clientId = null;
            var    message  = signOutMessageCookie.Read(id);

            if (message != null)
            {
                clientId = message.ClientId;
            }
            await context.CallUserServiceSignOutAsync(clientId);

            if (user != null && user.Identity.IsAuthenticated)
            {
                await eventService.RaiseLogoutEventAsync(user, id, message);
            }

            return(await RenderLoggedOutPage(id));

            //return await Login(id);
        }