void InvokeCheckCredential(string serviceId, JwtAuthorizationContext context)
        {
            var serviceContainer = _container.Resolve <IServiceEntryContainer>();
            var services         = serviceContainer.GetServiceEntry();

            if (services.Any())
            {
                var service = services.FirstOrDefault(x => x.Descriptor.Id == serviceId);
                if (service != null)
                {
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("context", context);
                    service.Func(dic, null);
                }
            }
        }
        void InvokeCheckCredential(string serviceId, JwtAuthorizationContext context)
        {
            var serviceContainer = _container.Resolve <IServiceEntryContainer>();
            var services         = serviceContainer.GetServiceEntry();

            if (services.Any())
            {
                var service = services.FirstOrDefault(x => x.Descriptor.Id == serviceId);
                if (service != null)
                {
                    Dictionary <string, object> dic = new Dictionary <string, object>();
                    dic.Add("context", context);
                    service.Func(dic, null);
                    return;
                }
            }
            throw new EntryPointNotFoundException($"{serviceId} not found, cannot check token generate credential");
        }
        Task CreateToken(RemoteCallerContext context)
        {
            if (string.IsNullOrEmpty(_options.CheckCredentialServiceId))
            {
                return(context.Response.WriteAsync(context.TransportMessage.Id, new JimuRemoteCallResultData
                {
                    ErrorMsg = $"JwtAuthorizationOptions.CheckCredentialServiceId  must be provided",
                    ErrorCode = "500"
                }));
            }
            JwtAuthorizationContext jwtAuthorizationContext = new JwtAuthorizationContext(_options, context.RemoteInvokeMessage);

            //_options.CheckCredential(jwtAuthorizationContext);
            InvokeCheckCredential(_options.CheckCredentialServiceId, jwtAuthorizationContext);
            if (jwtAuthorizationContext.IsRejected)
            {
                return(context.Response.WriteAsync(context.TransportMessage.Id, new JimuRemoteCallResultData
                {
                    ErrorMsg = $"{jwtAuthorizationContext.Error}, {jwtAuthorizationContext.ErrorDescription}",
                    ErrorCode = "400"
                }));
            }

            var payload = jwtAuthorizationContext.GetPayload();
            var token   = JWT.Encode(payload, Encoding.ASCII.GetBytes(_options.SecretKey), JwsAlgorithm.HS256);

            var result = new ExpandoObject() as IDictionary <string, object>;

            result["access_token"] = token;
            if (_options.ValidateLifetime)
            {
                result["expired_in"] = payload["exp"];
            }

            return(context.Response.WriteAsync(context.TransportMessage.Id, new JimuRemoteCallResultData
            {
                Result = result
            }));
        }