Esempio n. 1
0
        /// <summary>
        /// 授权
        /// </summary>
        /// <returns></returns>
        public ActionResult Access()
        {
            FormStringControl queryControl = new FormStringControl(Request.Url.Query);
            var clientID = queryControl.GetParamValue("client_id");
            var userID   = User.Identity.GetUserId();

            _ticketStore.Set("TemporaryAuthorization" + clientID + "$" + userID, "", 2);
            return(Redirect(Url.Content("~/") + EndPointConfig.AuthorizeEndpointPath.TrimStart('/') + Request.Url.Query));
        }
Esempio n. 2
0
        // GET: OAuth/Grant
        public ActionResult Index()
        {
            FormStringControl queryControl = new FormStringControl(Request.Url.Query);

            ViewBag.Scope = queryControl.GetParamValue("Scope");;
            var clientIDStr = queryControl.GetParamValue("client_id");
            int clientID;

            if (string.IsNullOrEmpty(clientIDStr) || !int.TryParse(clientIDStr, out clientID))
            {
                throw new BusinessException("client_id不存在.");
            }
            var app = _appService.Query(new AppDTO
            {
                ClientID = clientID
            }, null).ToList().FirstOrDefault();

            if (app == null)
            {
                throw new BusinessException("该client_id不存在应用.");
            }
            ViewBag.AccessUrl = Url.Content("~/") + EndPointConfig.AuthorizeGrantAccess + Request.Url.Query;
            return(View(_typeAdapter.Adapt <AppDTO>(app)));
        }
Esempio n. 3
0
        public ActionResult Index(UserDTO userParam)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var isRemenber = Request.Form["isRemenber"].Contains("true");
            var roleName   = Request.Form["ddl_Role"];
            var result     = _userService.Login(userParam.Name, userParam.Password);

            if (result.Success)
            {
                var user            = result.Data;
                var cookiesIdentity = ClaimsIdentityCreate.GenerateUserIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                var role            = user.Roles.Select(s => s.Name).FirstOrDefault(t => t == roleName);
                if (string.IsNullOrEmpty(role))
                {
                    ModelState.AddModelError("", "角色选择不正确.");
                    return(View());
                }
                cookiesIdentity.AddRole(role);
                Request.GetOwinContext().Request.Context.Authentication.SignIn(new
                                                                               AuthenticationProperties
                {
                    IsPersistent = isRemenber
                }, cookiesIdentity);
                var queryStr = Request.QueryString["Query"];
                if (!string.IsNullOrEmpty(queryStr))
                {
                    FormStringControl queryControl = new FormStringControl(queryStr);
                    if (queryControl.ContainParamName("ReturnUrl"))
                    {
                        return(Redirect(queryControl.GetParamValue("ReturnUrl")));
                    }
                }
                return(Redirect("~/Admin/Home"));
            }
            ModelState.AddModelError("", result.Message);
            return(View());
        }