title: Token access blocked when posting request from published Azure function
body: <p>I am struggling to get a token from &quot;https://login.microsoftonline.com/common/oauth2/token&quot; with an Azure function by a post-request. The token will give permissions to access SharePoint though CSOM. Here is my code snippet with the post request:</p>
  <pre><code>var clientId = defaultAADAppId;
  var body = $&quot;resource={resource}&amp;client_id={clientId}&amp;grant_type=password&amp;username={HttpUtility.UrlEncode(username)}&amp;password={HttpUtility.UrlEncode(password)}&quot;;
  using (var stringContent = new StringContent(body, Encoding.UTF8, &quot;application/x-www-form-urlencoded&quot;))
  {
      var result = await httpClient.PostAsync(tokenEndpoint, stringContent);
      var tokenResult = JsonSerializer.Deserialize&lt;JsonElement&gt;(result);
      var token = tokenResult.GetProperty(&quot;access_token&quot;).GetString();
  }
  </code></pre>
  <p>When testing locally, both when running the function in Visual studio and when I try with Postman, I am able to achieve an access token. However, as soon as I publish the function to my Function app in Azure I receive the following error message:</p>
  <p>&quot;AADSTS53003: Access has been blocked by Conditional Access policies. The access policy does not allow token issuance&quot;</p>
  <p>I have enabled an app registration in the portal and as mentioned, it all works fine until I publish everything to Azure.</p>
  <p>Any ideas on how to solve this?</p>