Exemplo n.º 1
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            mUser user = user_get.Login(model.UserName, model.Password);

            if (user == null)
            {
                ModelState.AddModelError("", "提供的用户名或密码不正确。");
                return(View(model));
            }
            var roles = user_get.RoleGetByuser(user.Id);
            var auths = user_get.AuthGetByuser(user.Id);

            authentication.SetAuthCookie(this.HttpContext, AuthenticationTicketBuilder.CreateTicket(user, roles, auths));
            if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1)
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToAction("Use", "Seat"));
            }
        }
        private AuthenticationTicket BuildIdentityFromEasyAuthMeJson(JObject payload)
        {
            var providerName = payload["provider_name"].Value <string>();

            this.Logger.LogDebug($"payload was fetched from easyauth me json, provider: {providerName}");

            this.Logger.LogInformation("building claims from payload...");
            return(AuthenticationTicketBuilder.Build(
                       JsonConvert.DeserializeObject <IEnumerable <AADClaimsModel> >(payload["user_claims"].ToString()),
                       providerName,
                       this.defaultOptions.GetProviderOptions()
                       ));
        }
Exemplo n.º 3
0
        private AuthenticationTicket BuildIdentityFromEasyAuthMeJson(JObject payload)
        {
            var providerName = payload["provider_name"].Value <string>();

            this.Logger.LogDebug($"payload was fetched from easyauth me json, provider: {providerName}");

            this.Logger.LogInformation("building claims from payload...");
            return(AuthenticationTicketBuilder.Build(
                       payload["user_claims"].Children <JObject>(),
                       providerName,
                       this.Options
                       ));
        }
Exemplo n.º 4
0
        private AuthenticationTicket BuildIdentityFromEasyAuthRequestHeaders()
        {
            var providerName = this.Headers[PrincipalIdpHeaderName][0];

            this.Logger.LogDebug($"payload was fetched from easyauth me json, provider: {providerName}");

            this.Logger.LogInformation("building claims from payload...");
            var xMsClientPrincipal = JObject.Parse(
                Encoding.UTF8.GetString(
                    Convert.FromBase64String(this.Headers[PrincipalObjectHeader][0])
                    )
                );

            var claims = xMsClientPrincipal["claims"].Children <JObject>();

            return(AuthenticationTicketBuilder.Build(claims, providerName, this.Options));
        }
Exemplo n.º 5
0
        private AuthenticationTicket BuildIdentityFromEasyAuthMeJson(JObject payload)
        {
            var providerName = payload["provider_name"].Value <string>();

            this.Logger.LogDebug($"payload was fetched from easyauth me json, provider: {providerName}");

            this.Logger.LogInformation("building claims from payload...");
            var ticket = AuthenticationTicketBuilder.Build(
                JsonConvert.DeserializeObject <IEnumerable <AADClaimsModel> >(payload["user_claims"].ToString()),
                providerName,
                this.defaultOptions.GetProviderOptions()
                );

            var name        = ticket.Principal.Claims?.FirstOrDefault(c => c.Type == ClaimTypes.Name)?.Value ?? string.Empty;
            var roles       = ticket.Principal.Claims?.Where(c => c.Type == ClaimTypes.Role);
            var rolesString = string.Join(", ", roles?.Select(r => r.Value)) ?? string.Empty;

            this.Logger.LogInformation($"identity name: '{ name }' with roles: [{ rolesString }]");

            return(ticket);
        }
Exemplo n.º 6
0
        public ActionResult Register(RegisterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (user_get.UserCheckNameExist(model.UserName))
            {
                ModelState.AddModelError("", "用户名已存在。");
                return(View(model));
            }
            mUser user = new mUser {
                Name     = model.UserName,
                Password = model.Password
            };

            user_sub.UserAdd(user);
            //user_sub.UserAddByrole(user, "Guest");
            var roles = user_get.RoleGetByuser(user.Id);
            var auths = user_get.AuthGetByuser(user.Id);

            authentication.SetAuthCookie(this.HttpContext, AuthenticationTicketBuilder.CreateTicket(user, roles, auths));
            return(RedirectToAction("Use", "Seat"));
        }