Beispiel #1
0
        private async Task <IEndpointResult> ProcessSignInAsync(HttpContext context, SignInRequestMessage signin)
        {
            if (context.User.Identity.IsAuthenticated)
            {
                logger.LogDebug("User in WS-Federation signin request: {subjectId}", context.User.GetSubjectId());
            }
            else
            {
                logger.LogDebug("No user present in WS-Federation signin request");
            }

            // validate request
            var result = await signinValidator.ValidateAsync(signin, context.User);

            if (result.IsError)
            {
                throw new Exception(result.Error);
            }

            if (result.SignInRequired)
            {
                var wsFedRequest = context.Request.QueryString.Value;
                return(new WsFederationLoginPageResult(wsFedRequest));
            }

            // create protocol response
            var responseMessage = await generator.GenerateResponseAsync(result);

            await sessionService.AddClientIdAsync(result.Client.ClientId);

            return(new SignInResult(responseMessage));
        }
Beispiel #2
0
        private async Task <IActionResult> ProcessSignInAsync(WsFederationMessage signin, ClaimsPrincipal user)
        {
            if (user != null && user.Identity.IsAuthenticated)
            {
                _logger.LogDebug("User in WS-Federation signin request: {subjectId}", user.GetSubjectId());
            }
            else
            {
                _logger.LogDebug("No user present in WS-Federation signin request");
            }

            // validate request
            var result = await _signinValidator.ValidateAsync(signin, user);

            if (result.IsError)
            {
                throw new Exception(result.Error);
            }

            if (result.SignInRequired)
            {
                var returnUrl = Url.Action("Index");
                // remove wfresh parameter to ensure we don't trigger sign in after the user signes in
                var query = Request.Query.Where(q => !q.Key.Equals("wfresh", StringComparison.OrdinalIgnoreCase));
                returnUrl = returnUrl.AddQueryString(QueryString.Create(query).Value);

                var loginUrl = Request.PathBase + _options.UserInteraction.LoginUrl;
                var url      = loginUrl.AddQueryString(_options.UserInteraction.LoginReturnUrlParameter, returnUrl);

                return(Redirect(url));
            }
            else
            {
                // create protocol response
                var responseMessage = await _generator.GenerateResponseAsync(result);

                await _userSession.AddClientIdAsync(result.Client.ClientId);

                return(new SignInResult(responseMessage));
            }
        }
        private async Task <IActionResult> ProcessSignInAsync(SignInRequestMessage signin, ClaimsPrincipal user)
        {
            if (user.Identity.IsAuthenticated)
            {
                _logger.LogDebug("User in WS-Federation signin request: {subjectId}", user.GetSubjectId());
            }
            else
            {
                _logger.LogDebug("No user present in WS-Federation signin request");
            }

            // validate request
            var result = await _signinValidator.ValidateAsync(signin, user);

            if (result.IsError)
            {
                throw new Exception(result.Error);
            }

            if (result.SignInRequired)
            {
                var returnUrl = Url.Action("Index");
                returnUrl = returnUrl.AddQueryString(Request.QueryString.Value);

                var loginUrl = _options.UserInteraction.LoginUrl;
                var url      = loginUrl.AddQueryString(_options.UserInteraction.LoginReturnUrlParameter, returnUrl);

                return(Redirect(url));
            }
            else
            {
                // create protocol response
                var responseMessage = await _generator.GenerateResponseAsync(result);

                await _sessionService.AddClientIdAsync(result.Client.ClientId);

                return(new SignInResult(responseMessage));
            }
        }