title: How to download a file from Sharepoint Online using an access token
body: <p>I know this has been asked quite a few times already, but I have not been able to find a working solution to my problem yet.</p>
  
  <p><strong>Problem:</strong></p>
  
  <p>I need to download a file from a Sharepoint Online site using a C# app using CSOM and a JWT token. When I come to the point where I call this method</p>
  
  <pre><code>File.OpenBinaryDirect(ClientContext context, string serverRelativeUrl);
  </code></pre>
  
  <p>I get a 401 Unauthorized error.</p>
  
  <p>I authenticate my application in Azure AD using a certificate. It works fine for accessing SharePoint lists, list items and so on, which means that downloading files is the only part where I get this error message.</p>
  
  <p><strong>What I've done</strong></p>
  
  <p>I've done some research on the matter and found one thread on MSDN from 2 years ago (<a href="https://social.msdn.microsoft.com/Forums/office/en-US/7746d857-d351-49cc-b2f0-496663239e02/how-to-download-a-file-version-from-office-365-using-csom?forum=sharepointdevelopment" rel="nofollow">https://social.msdn.microsoft.com/Forums/office/en-US/7746d857-d351-49cc-b2f0-496663239e02/how-to-download-a-file-version-from-office-365-using-csom?forum=sharepointdevelopment</a>) mentioning that it was impossible to download files from SP using access tokens. </p>
  
  <p>This is an old thread, so something must have changed since then, but so far I have not been able to find a working solution.</p>
  
  <p>All the articles I come across on the Internet mention providing user credentials to the context. But my client insists on using certificates. Because of that I cannot use this approach</p>
  
  <p><strong>Question</strong></p>
  
  <p>Is there a way I can download files from Sharepoint Online using a JWT token?</p>