How .caller property is assigned in a 'shared' function parameter?

I’m building a browser client that talks to Motoko canister and would like to take advantage of the passed Principal in a shared function, but I cannot find any resources on how a function that is marked as ‘shared’, gets the ‘caller’ [Principal] property of the passed object assigned.

public shared(msg) func howMsgDotCallerIsAssigned() : async Text {
  // how msg.caller is assigned?
  // are there any docs explaining it?
  return "I don't know";

I’m not sure if it’s assigned by the system itself based on some arbitrary variables or by the user? If it is assigned by the system, are there any variables modifiable by the client (the variables that make up the Principal)?

I know that the msg.caller can be used in simple authentication and that it defaults to “2vxsx-fae”.


Your js agent will sign the message with your principal and that will be msg.caller. It is assigned by the replica to that value.

If you log in and constitute the agent with that identity that anon default will go away and be replaced with your principal.


Thanks. This was the point that I was missing.