You do not have to be a US Citizen to get a medical marijuana recommendation in the state of California.
You do need to be in the state of CA at the time of the doctors consultation (as per Telehealth laws). However, if you are located internationally, that will be fine too. You just cannot be in another US state (other than CA).
With regards to the purchase of cannabis. Most dispensaries will ask you for some type of proof of CA residence before they will sell you anything. Others may be more lenient. There is nothing in CA law that requires you to be a resident, but most follow this rule unfortunately.
You may be able to buy cannabis from a dispensary using your foreign passport, you CA recommendation and some other type of ID indicating residence (like a lease or utility bill). If you have any doubts about this, call your local dispensary and ask.
mark