How to see an object by looking throug another object?
As Millad already pointed out, this would be done with the Light Path node.

Material for the portal is just a refraction shader with an index of refraction set to 1 (so it doesnt actually refract the objects behind it).



The "magic" happens in the material you want to see through your portal.
use a mix shader to mix a transparent node (be sure the color of the node is pure white. its often a bit grey per default) and the actual material of your object. I used an emission shader just for an easier demonstration but pretty much everything works here. THere could be some problems with refration materials making objects visible that are not supposed to be visible. If you stumble across this problem, let me know.

for the factor input use the boferementioned light path node > transmission depth.