lilililizheng opened a new issue, #10725:
URL: https://github.com/apache/apisix/issues/10725

   ### Description
   
   I want to use consumer in the stream module, for example: In xrpc, I 
received the downstream data and resolved the token. I wanted to invoke the 
interface in the jwt plug-in to verify the token (token is generated by the jwt 
interface), but I found that there was no consumer configuration in the stream. 
I call 
   require("apisix.consumer").init_worker() and consumer_group.init_worker() in 
stream_init_worker
   , but there is still no consumer. How can I solve it
   
   this is my code:
   local function _stream_token(jwt_token)
       local jwt_obj = jwt:load_jwt(jwt_token)
       core.log.info("jwt object: ", core.json.delay_encode(jwt_obj))
       if not jwt_obj.valid then
           print("11111111111111111111111111111111")
           return false
       end
   
       local sessid = jwt_obj.payload.sessid
       local client_type = jwt_obj.payload.client_type
   
       local user_key = jwt_obj.payload and jwt_obj.payload.key
       if not user_key then
           print("22222222222222222222222222222")
           return false
       end
   
       local consumer_conf = consumer_mod.plugin(plugin_name)
       if not consumer_conf then  
       print("333333333333333333333333333333") 
          return false
       end
   
       local consumers = consumer_mod.consumers_kv(plugin_name, consumer_conf, 
"key")
   
       local consumer = consumers[user_key]
       if not consumer then
           print("44444444444444444444444444444")
           return false
       end
   
   
       local res = check_sessid(consumer,sessid,client_type)
       if res ~= true then
           print("55555555555555555555555555555555")
           return false
       end
   
       -- core.log.info("consumer: ", core.json.delay_encode(consumer))
   
       local auth_secret, err = algorithm_handler(consumer)
       if not auth_secret then
           print("66666666666666666666666666666")
           return false
       end
       local claim_specs = jwt:get_default_validation_options(jwt_obj)
       claim_specs.lifetime_grace_period = 
consumer.auth_conf.lifetime_grace_period
   
       jwt_obj = jwt:verify_jwt_obj(auth_secret, jwt_obj, claim_specs)
       core.log.info("jwt object: ", core.json.delay_encode(jwt_obj))
   
       if not jwt_obj.verified then
           core.log.warn("failed to verify jwt: ", jwt_obj.reason)
           return false
       end
   
       consumer_mod.attach_consumer(ctx, consumer, consumer_conf)
       
       return true
   end
   
   printed print("333333333333333333333333333333") 
   
   ### Environment
   
   - APISIX version (run `apisix version`):
   - Operating system (run `uname -a`):
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`):
   - APISIX Dashboard version, if relevant:
   - Plugin runner version, for issues related to plugin runners:
   - LuaRocks version, for installation issues (run `luarocks --version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to