I have got the following method to get a token from the Service Principal or the client of my webapp on Azure. It seems to work fine when there are no exceptions but causes my a