title: Authenticating Azure Storage with system assigned Identity from Azure Functions
body: <p>I want to use system assigned Identity from Azure Functions to authenticate and read from storage account. I got the following code for .NET. I was looking for equivalent code in Java. Thanks in advance.</p>
  <pre class="lang-cs prettyprint-override"><code>public static class Function1
  {
      [FunctionName(&quot;WebHook-Func&quot;)]
      public static async Task&lt;IActionResult&gt; Run(
          [HttpTrigger(AuthorizationLevel.Function, &quot;get&quot;, &quot;post&quot;, Route = null)] HttpRequest req,
          ILogger log)
      {
          log.LogInformation(&quot;C# HTTP trigger function processed a request.&quot;);
  
          var azureServiceTokenProvider = new AzureServiceTokenProvider();
          string accessToken = await azureServiceTokenProvider.GetAccessTokenAsync(&quot;https://storage.azure.com/&quot;);
          TokenCredential creds = new TokenCredential(accessToken);
  
          log.LogInformation($&quot;Token: {accessToken}&quot;);
  
          StorageCredentials storageCreds = new StorageCredentials(creds);
  
          try
          {
              CloudBlobClient client = new CloudBlobClient(new StorageUri(new Uri(&quot;https://&lt;storageAccount&gt;.blob.core.windows.net&quot;)), storageCreds);
              CloudBlobContainer container = client.GetContainerReference(&quot;fltd&quot;);
              CloudBlockBlob blob = container.GetBlockBlobReference(&quot;shopping.txt&quot;);
  
              string content = await blob.DownloadTextAsync();
  
              return (ActionResult)new OkObjectResult($&quot;File contents: {content}&quot;);
          }catch(Exception ex)
          {
              return new BadRequestObjectResult($&quot;Exception when calling web hook: {ex.StackTrace} {ex.Message}&quot;);
          }
      }
  }
  </code></pre>