How to get an instance of UriInfo from an SPI

Our usecase: we want to send a welcome email for new federated users (created manually by our admins from a third system) with a link to set their password.

I created an spi which reads from a kafka stream and creates a required action token and the last thing missing is the UriInfo (normally read from the context field in the keycloak session instance but in my case it is empty)

I am creating the session manually (by using the keycloaksessionfactory since I implemented EventListenerProviderFactory), and the keycloak context that holds the uriInfo is empty. I have been stepping through multiple keycloak flows to find out where it is set in the default case but could not find it.

I tested the same code via rest endpoint and got the link since rest endpoint populates session context:

 String generateLink(UserModel user, RealmModel realm, KeycloakSession session) {
     ExecuteActionsActionToken token = new ExecuteActionsActionToken(user.getId(), 
         Time.currentTime() + 3600, List.of("UPDATE_PASSWORD"), null, "myclient");

    UriBuilder builder = LoginActionsService.actionTokenProcessor(session.getContext().getUri());
    builder.queryParam("key", token.serialize(session, realm, session.getContext().getUri()));