public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model)
        {
            Response response;

            if (model.ReturnUrl != null)
            {
                response = nancyModule.Response.AsRedirect("~" + model.ReturnUrl);
            }
            else
            {
                response = nancyModule.AsRedirectQueryStringOrDefault("~/");

                if (nancyModule.IsAuthenticated())
                {
                    response = nancyModule.AsRedirectQueryStringOrDefault("~/account/#identityProviders");
                }
            }

            if (model.Exception != null)
            {
                nancyModule.Request.AddAlertMessage("error", model.Exception.Message);
            }
            else
            {
                UserInformation information = model.AuthenticatedClient.UserInformation;
                var             claims      = new List <Claim>();
                claims.Add(new Claim(ClaimTypes.NameIdentifier, information.Id));
                claims.Add(new Claim(ClaimTypes.AuthenticationMethod, model.AuthenticatedClient.ProviderName));

                if (!String.IsNullOrEmpty(information.UserName))
                {
                    claims.Add(new Claim(ClaimTypes.Name, information.UserName));
                }

                if (!String.IsNullOrEmpty(information.Email))
                {
                    claims.Add(new Claim(ClaimTypes.Email, information.Email));
                }

                nancyModule.SignIn(claims);
            }

            return(response);
        }
Пример #2
0
        public static Response SignIn(this NancyModule module, IEnumerable <Claim> claims)
        {
            var env         = Get <IDictionary <string, object> >(module.Context.Items, NancyOwinHost.RequestEnvironmentKey);
            var owinContext = new OwinContext(env);

            var identity = new ClaimsIdentity(claims, Constants.JabbRAuthType);

            owinContext.Authentication.SignIn(identity);

            return(module.AsRedirectQueryStringOrDefault("~/"));
        }
Пример #3
0
        public static Response SignIn(this NancyModule module, IEnumerable <Claim> claims)
        {
            var requestEnvironment = (IDictionary <string, object>)module.Context.Items["OWIN_REQUEST_ENVIRONMENT"];
            var owinContext        = new OwinContext(requestEnvironment);

            var identity = new ClaimsIdentity(claims, Constants.CrossoutDBAuthType);

            owinContext.Authentication.SignIn(identity);

            return(module.AsRedirectQueryStringOrDefault("~/"));
        }
Пример #4
0
        public dynamic Process(NancyModule nancyModule, AuthenticateCallbackData model)
        {
            if (model.Exception != null)
            {
                throw new NotImplementedException("Login failure", model.Exception);
            }

            CrossoutUser loggedInUser = null;

            if (nancyModule.Context.CurrentUser != null)
            {
                loggedInUser = userRepository.LoadUser(nancyModule.Context.CurrentUser.UserName);
            }

            if (loggedInUser == null)
            {
                UserInformation userInfo = model.AuthenticatedClient.UserInformation;

                var user = userRepository.LoadUser(userInfo.Id);

                if (user == CrossoutUser.EmptyUser)
                {
                    userRepository.SaveUser(new CrossoutUser
                    {
                        AuthEmail    = userInfo.Email,
                        AuthId       = userInfo.Id,
                        AuthName     = userInfo.Name,
                        AuthUsername = userInfo.UserName
                    });
                    user = userRepository.LoadUser(userInfo.Id);
                }
                return(nancyModule.LoginAndRedirect(user.Guid, null, "~/admin"));
            }

            return(nancyModule.AsRedirectQueryStringOrDefault("~/admin"));
        }