How to restrict different apps access programmatically

I want to assign only some particular apps to particular users while the user invitation is sending. Other apps should not be visible for them. How can i make this possible by using code ??