コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public Task Invoke(HttpContext httpContext)
        {
            //检测是否包含'Authorization'请求头,如果不包含则直接放行
            if (!httpContext.Request.Headers.ContainsKey("Authorization"))
            {
                return(_next(httpContext));
            }
            var tokenHeader = httpContext.Request.Headers["Authorization"];

            tokenHeader = tokenHeader.ToString().Substring("Bearer ".Length).Trim();

            TokenModel tm = JwtHelperb.SerializeJWT(tokenHeader);

            //BaseBLL.TokenModel = tm;//将tokenModel存入baseBll

            //授权
            var claimList = new List <Claim>();
            var claim     = new Claim(ClaimTypes.Role, tm.Role);

            claimList.Add(claim);
            var identity  = new ClaimsIdentity(claimList);
            var principal = new ClaimsPrincipal(identity);

            httpContext.User = principal;

            return(_next(httpContext));
        }
コード例 #2
0
 public ApiJsonResultData PageList()
 {
     return(new ApiJsonResultData().RunWithTry(y =>
     {
         var tokenHeader = HttpContext.Request.Headers["Authorization"];
         tokenHeader = tokenHeader.ToString().Substring("Bearer ".Length).Trim();
         TokenModel tm = JwtHelperb.SerializeJWT(tokenHeader);
         y.Data = tm;
     }));
 }
コード例 #3
0
 public ApiJsonResultData GetJWTStr()
 {
     return(new ApiJsonResultData().RunWithTry(y =>
     {
         var data = new TokenModel
         {
             Uid = "260C8ACC-ECA6-44E7-9C02-32A6A35A7CFA", Project = "MedicalInsurance", Role = "User", TokenType = "web"
         };
         y.Data = JwtHelperb.IssueJWT(data);
     }));
 }