<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Axel Joigneau on Medium]]></title>
        <description><![CDATA[Stories by Axel Joigneau on Medium]]></description>
        <link>https://medium.com/@axel.joigneau?source=rss-a68b09c55e03------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ykCOhGzj7o86BdFLDLHnQw.jpeg</url>
            <title>Stories by Axel Joigneau on Medium</title>
            <link>https://medium.com/@axel.joigneau?source=rss-a68b09c55e03------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 18:28:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@axel.joigneau/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[7 Hidden Pitfalls while integrating a SharePoint File Picker]]></title>
            <link>https://medium.com/doctrine/7-hidden-pitfalls-while-integrating-a-sharepoint-file-picker-ebbfe6451b68?source=rss-a68b09c55e03------2</link>
            <guid isPermaLink="false">https://medium.com/p/ebbfe6451b68</guid>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[sharepoint]]></category>
            <category><![CDATA[file-upload]]></category>
            <dc:creator><![CDATA[Axel Joigneau]]></dc:creator>
            <pubDate>Thu, 13 Nov 2025 08:53:30 GMT</pubDate>
            <atom:updated>2025-11-13T12:51:45.773Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K0B_QcnrlbEGctY1jSFNpA.png" /></figure><h3>Context: Private Enterprise Documents</h3><p>At Doctrine, our web application can extract a lot of value from legal documents — especially using AI tools.</p><p>Everything worked perfectly with the local files from our users’ computers, but we realized we could go even further by using the valuable data that lies in law firms’ private and internal storage.</p><p>Our goal quickly became clear: make it possible for our AI tools to work on private internal data while keeping everything strictly secure and compliant.</p><p>Hosting documents elsewhere was out of the question. Storing them directly in our own database wasn’t the kind of experiment we wanted to start with. Staying true to our core value, <em>“Release early”</em>, we looked for the simplest solution that would let users access their own files through our platform — and ideally, through a Document Management System already popular among our users.</p><p>That’s where the SharePoint File Picker came in — Microsoft’s official tool that allows users to select files from SharePoint or OneDrive, with permissions and security already built in.</p><h3>Design Philosophy: Simplicity First</h3><p>At Doctrine, simplicity is a core principle — both in user experience and in technical design.</p><p>So instead of building a custom connector to Microsoft Graph or maintaining our own file browser, we wanted to rely on the simplest existing building block: Microsoft’s native File Picker.</p><p>No custom OAuth flows.<br>No proxy backend.<br>No reinventing file access logic.</p><p>Just a standard, well-supported Microsoft interface that:</p><ul><li>Lets users pick files in an environment they already know (SharePoint/OneDrive)</li><li>Automatically respects existing permissions</li><li>Uses Microsoft 365 authentication out of the box</li><li>Never exposes or stores files outside the organization’s boundaries</li></ul><p>Nothing could go wrong… right?</p><p>As we quickly learned, simplicity on the surface often hides real technical complexity underneath. Between permission flows, token handling, and inconsistent SDK behavior across versions, the File Picker journey turned out to be a lot more intricate than expected.</p><p>Before diving into the problems we encountered, here’s the basic <a href="https://github.com/OneDrive/samples/tree/master/samples/file-picking/javascript-basic">JavaScript code</a> our implementation was based on, along with <a href="https://learn.microsoft.com/en-us/onedrive/developer/controls/file-pickers/?view=odsp-graph-online">Microsoft Entra’s setup tutorial</a>.</p><p>Let’s now look at the <strong>7 most common pitfalls</strong> we faced while integrating the modern Microsoft 365 / SharePoint File Picker (v8) — what causes them, and how to avoid them.</p><h3>Pitfall 1: Token expiration</h3><p>Access tokens from Microsoft Graph expire after ~1 hour.<br>Without silent token refresh, your picker suddenly stops working mid-session.</p><p><strong>Fix:</strong> use MSAL’s acquireTokenSilent() before every picker launch. The “refresh token” has a lifetime of 90 days and allows you to get a new Microsoft Graph token as soon as it expires.</p><p>For those who were wondering, this is the part that makes the permission User.Read mandatory in your app. Your final permission settings must look like this :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vYGL9OqJ18Qh_k0fnO8ogA.png" /></figure><h3>Pitfall 2: Permissions are persisted and linked to the user</h3><p>You could choose to control the scopes from your web app like this (not recommended) :</p><pre>await msalInstance.acquireTokenSilent({scopes: [&#39;File.Read&#39;, &#39;Sites.Read.All&#39;, &#39;User.Read&#39;]})</pre><p>But the cleanest way is to choose default scopes and to configure permissions from Microsoft Entra directly.</p><pre>await msalInstance.acquireTokenSilent({scopes: [&#39;https://graph.microsoft.com/.default&#39;]})</pre><p>When using the .default scope, Entra ID returns all permissions that have previously been consented for that app.<br>If you remove a permission (e.g. Sites.Read.All) from your app registration, users who already consented will still receive tokens with that scope until their consent is revoked or expires.<br>However, <strong>new users</strong> will no longer get that permission — because it’s no longer available for consent.</p><h3>Pitfall 3: Missing redirect URI</h3><p>Even though the SharePoint file picker itself doesn’t <em>use</em> the redirect URI directly, you still need to configure it — because the underlying <strong>MSAL authentication flow</strong> requires it as part of the OAuth handshake.</p><p>The redirect URI acts as a “return address” for Entra ID to send tokens back to your app after the user signs in. Without it, the sign-in process has nowhere to return the access token, and the entire auth flow breaks.</p><p>If your redirect URI isn’t registered in Entra ID (formerly Azure AD), auth fails:</p><blockquote><em>“AADB2C90006: The redirect URI is not registered.”</em></blockquote><p><strong>Fix:</strong> register every environment (local, staging, prod) explicitly like in this screenshot :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NP7dCd018Vn1zUiW7sd_Hg.png" /></figure><h3>Pitfall 4: Folders can still be selected</h3><p>Even with typesAndSources.mode = &#39;files&#39;, folders sometimes appear selectable, especially in the Shared part. But the validation button will appear disabled if a folder is selected while in “files only” mode.</p><p><strong>Fix:</strong> the most user-friendly approach was to allow files &amp; folders selection using mode: &#39;all&#39; and manually filter selections in your callback.</p><h3>Pitfall 5: Recursive fetching from SharePoint</h3><p>When letting users select folders, recursive API calls can easily hit Graph throttling.</p><p><strong>Fix: </strong>do not forget to early stop your recursion when reaching a specific file count or size limits (100 files or 100MB for example), and pair it with an informational message for the user stating you only picked the first 100 files.</p><pre>MAX_FILE_COUNT = 100<br>MAX_FILE_SIZE = 100_000_000 // 95MB<br><br>const fetchFilesRecursively = async (<br>  driveId: string,<br>  folderId: string,<br>  files: SPItem[] = []<br>): Promise&lt;void&gt; =&gt; {<br>  const response = await fetch(<br>    `https://graph.microsoft.com/v1.0/drives/${driveId}/items/${folderId}/children`<br>  );<br>  const data: { value: SPItem[] } = await response.json();<br>  const children = data.value || [];<br><br>  for (const child of children) {<br>    const totalSize = files.reduce((sum, file) =&gt; sum + (file.size || 0), 0);<br>    if (files.length &gt;= MAX_FILE_COUNT || totalSize &gt;= MAX_FILE_SIZE) {<br>      // if we have exceeded limits (max file count or max size) we return early<br>      return true;<br>    }<br><br>    if (child.folder) {<br>      // Recursively go into subfolder<br>      const earlyStop = await fetchFilesRecursively(driveId, child.id, files);<br>      if (earlyStop) {<br>        return true;<br>      }<br>    } else {<br>      files.push(child);<br>    }<br>  }<br>  return false; // no early stop<br>};<br><br>// USAGE<br>const allFiles: SPItem[] = [];<br>let earlyStop = false;<br>let tooManyFilesWarning = false;<br><br>for (const item of sharePointItems) {<br>  if (item.folder) {<br>    // item is a folder, so we recursively fetch files in the folder and mutate allFiles<br>    earlyStop = await fetchFilesRecursively(<br>      item.parentReference.driveId,<br>      item.id,<br>      allFiles<br>    );<br>  } else {<br>    // simple file, just add it<br>    allFiles.push(item);<br>  }<br>  // Check if we have exceeded limits (max file count or max overall size)<br>  const totalSize = allFiles.reduce((sum, file) =&gt; sum + (file.size || 0, 0);<br>  if (<br>    earlyStop || allFiles.length &gt;= MAX_FILE_COUNT || totalSize &gt;= MAX_FILE_SIZE<br>  ) {<br>    tooManyFilesWarning = true;<br>    break;<br>  }<br>}<br><br>// use tooManyFilesWarning boolean to warn the user that all files could not be uploaded</pre><h3>Pitfall 6: Temporary download URLs</h3><p>The @microsoft.graph.downloadUrl expires after a short time.</p><p><strong>Fix: </strong>download or process the file immediately; don’t persist the URL in a database for example.</p><pre>const acceptedFiles = await Promise.all(<br>  sharePointItems.map(async (item: SPItem) =&gt; {<br>    // query Microsoft Graph to get the downloadUrl<br>    const fileInfoResponse = await fetch(<br>      `https://graph.microsoft.com/v1.0/drives/${item.parentReference.driveId}/items/${item.id}`<br>    );<br>    const fileInfo = await fileInfoResponse.json();<br>    const downloadUrl = fileInfo[&#39;@microsoft.graph.downloadUrl&#39;];<br><br>    // fetch the downloadUrl to create the file from blob<br>    const response = await fetch(downloadUrl);<br>    const blob = await response.blob();<br>    return new File([blob], fileInfo.name, { type: blob.type });<br>  })<br>);<br>handleSelectedFiles(acceptedFiles);</pre><h3>Pitfall 7: Popup blocked</h3><p>Some browsers like Google Chrome often block the appearance of new popups</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*LH9wjU6C3Kb6djYltZlX5g.png" /></figure><p>Although this is not a major problem, the user experience feels degraded when additional clicks are implied to make it work.</p><p><strong>Fix:</strong> Don’t forget to allow popups with this line :</p><pre>iframe.setAttribute(&#39;sandbox&#39;,&#39;allow-popups&#39;)</pre><h3>Conclusion</h3><p>What looked like a straightforward integration ended up teaching us much more than expected.<br>The SharePoint File Picker is powerful and secure — but also surprisingly sensitive to small configuration details. Some of those “pitfalls,” from redirect URIs to permission scopes, weren’t random bugs at all — just the usual OAuth magic happening under the hood. Once we understood its flow, everything started running smoothly.</p><p>The good news is that once it’s properly set up, it becomes an excellent bridge between enterprise data and modern web apps.<br>For us, it allowed lawyers to safely bring their own knowledge base into our AI ecosystem — without ever leaving their Microsoft 365 environment.</p><p>This Picker also opened new doors: automating Microsoft Entra configuration through Infrastructure as Code, exploring integrations with Microsoft’s competitors, and even imagining our own document management system — storing data directly within our own infrastructure.</p><p>But that’s another story…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebbfe6451b68" width="1" height="1" alt=""><hr><p><a href="https://medium.com/doctrine/7-hidden-pitfalls-while-integrating-a-sharepoint-file-picker-ebbfe6451b68">7 Hidden Pitfalls while integrating a SharePoint File Picker</a> was originally published in <a href="https://medium.com/doctrine">Inside Doctrine</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>