Beispiel #1
0
        public TResult Login(string name, string pwd)
        {
            _Logger.LogInformation("登录中....");

            if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(pwd))
            {
                return(TResult.Fail("用户名/密码不能为空"));
            }
            else
            {
                ClaimsIdentity claimIdentity = new ClaimsIdentity();
                claimIdentity.AddClaim(new Claim(ClaimTypes.Name, name));
                claimIdentity.AddClaim(new Claim(ClaimTypes.Role, "AAA"));
                claimIdentity.AddClaim(new Claim("自定义组策略", "this is my custom policy"));


                claimIdentity.AddClaim(new Claim("UserID", "012345"));

                AuthenticationProperties properties = new AuthenticationProperties();

                properties.GetJwtAuthenticationProperties("ilbli_custom_key", DateTime.UtcNow.AddMinutes(10), claims: claimIdentity.Claims);

                string token = properties.GetTokenValue("ILBLI_Token");
                return(TResult.DataSuccess(token));
            }
        }