public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            try
            {
                UserBLL        userBLL        = new UserBLL();
                PermissionsBLL permissionsBLL = new PermissionsBLL();
                Encryptor      enc            = new Encryptor();
                UserBE         userToFind     = new UserBE()
                {
                    UserName = context.UserName,
                    Password = context.Password
                };
                var user = await Task.Run(() => userBLL.CheckUserName(userToFind));

                if (user.Id != Guid.Empty)
                {
                    if (user.Password == enc.Encrypt(context.Password))
                    {
                        user.Permissions = permissionsBLL.GetUserPermission(user);
                        var identity = new ClaimsIdentity(context.Options.AuthenticationType);
                        identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));

                        string userObj = JsonConvert.SerializeObject(user);
                        identity.AddClaim(new Claim("userObject", userObj));
                        identity.AddClaim(new Claim("LoggedOn", DateTime.Now.ToString()));
                        identity = ListPermissions(user.Permissions, identity);
                        //var additionalData = new AuthenticationProperties(new Dictionary<string, string>{
                        //   {
                        //        "role", Newtonsoft.Json.JsonConvert.SerializeObject(identity.userRoles)
                        //    }
                        //});
                        //var token = new AuthenticationTicket(identity,new AuthenticationProperties() { });
                        context.Validated(identity);
                    }
                    else
                    {
                        throw new BusinessException(Messages.PasswordNotOk);
                    }
                }
                else
                {
                    throw new BusinessException(Messages.UserNotExists);
                }
            }
            catch (BusinessException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
 public PermissionController()
 {
     this.permissionBLL = new PermissionsBLL();
 }