Пример #1
0
        //private static X509Certificate2 CreateCertificate()
        //{
        //    TkDebug.ThrowIfNoAppSetting();
        //    string fileName = Path.Combine(BaseAppSetting.Current.XmlPath, "YJC.Toolkit2.pfx");
        //    X509Certificate2 cer = new X509Certificate2(fileName, "helloworld", (X509KeyStorageFlags)32); //, (X509KeyStorageFlags)32 | X509KeyStorageFlags.Exportable
        //    return cer;
        //}

        public static string CreateEncodingInfo(IUserInfo userInfo, string hostValue, int?port)
        {
            if (userInfo is JWTUserInfo jwtInfo)
            {
                return(EncodeToJwt(jwtInfo));
            }
            else
            {
                if (userInfo.IsSupportTenant())
                {
                    jwtInfo = new JWTTetantUserInfo(userInfo)
                    {
                        Host = hostValue,
                        Port = port
                    }
                }
                ;
                else
                {
                    jwtInfo = new JWTUserInfo(userInfo)
                    {
                        Host = hostValue,
                        Port = port
                    }
                };
                return(EncodeToJwt(jwtInfo));
            }
        }
Пример #2
0
        public static JWTUserInfo DecodeFromJwt(string token)
        {
            string            json   = JWT.JWT.Decode(token, SecretKey); //fCertificate.GetRSAPrivateKey());
            JWTTetantUserInfo result = json.ReadJson <JWTTetantUserInfo>();

            if (string.IsNullOrEmpty(result.TenantId?.ToString()))
            {
                JWTUserInfo info = new JWTUserInfo(result);
                return(info);
            }
            else
            {
                return(result);
            }
        }
Пример #3
0
        private static void WriteJwt(HttpRequest request, HttpResponse response)
        {
            HttpContext context = HttpContextHelper.Current;
            var         user    = context.User;

            if (user is ToolkitClaimsPrincipal principal)
            {
                JWTUserInfo info = principal.UserInfo;
                if (info.UseRequestHeader)
                {
                    response.Headers[info.HeaderName] = request.Headers[info.HeaderName];
                }
                else
                {
                    response.Headers[info.HeaderName] = info.Token;
                }
            }
        }
Пример #4
0
        public static bool IsValidHost(JWTUserInfo userInfo, string host, int?port)
        {
            TkDebug.AssertArgumentNull(userInfo, nameof(userInfo), null);

            return(userInfo.Host == host && userInfo.Port == port);
        }
Пример #5
0
 public ToolkitClaimsPrincipal(JWTUserInfo info)
 {
     UserInfo = info;
 }