God was with Joseph, but Joseph was only dispensing the will of the Pharoah. He wasn’t gathering assets for himself when he was trading grain that sustained people for their lands and cattle.
God would oppose anything that would blaspheme Him in anything Joseph did. Pharaoh’s will could never take precedence.
Not to mention it was the idea of the people themselves to sell themselves to Pharaoh (Gen. 47:19).