Differentiation between the methods of obtaining the userPrincipal calling the function

Yes, that’s right. Otherwise someone could modify the frontend to impersonate anybody.

Here’s an example how we use both approaches in the same code base:

  • Use ic_cdk::api::caller() to get the real caller (e.g. here)
  • Pass it into a function (that’s fn my_func(caller: Principal), e.g. here) so that testing becomes easier. Tests are here, but none use different callers right now I think.
1 Like