title: Microsoft graph: Search as external user (guest)
body: <p>I am using the Graph API to search SharePoint like its described <a href="https://docs.microsoft.com/en-us/graph/search-concept-files" rel="nofollow noreferrer">here</a>.<br />
  For this I created an app with delegated permissions:</p>
  <blockquote>
  <p>Sites.ReadWrite.All Files.ReadWrite.All</p>
  </blockquote>
  <p>Now I can send a POST request to &quot;https://graph.microsoft.com/v1.0/search/query&quot; with the following body:</p>
  <pre><code>{   &quot;requests&quot;: [
      {
        &quot;entityTypes&quot;: [
          &quot;listItem&quot;
        ],
        &quot;query&quot;: {
          &quot;queryString&quot;: &quot;{SOME QUERY}&quot;
        },
        &quot;size&quot;: 100,
        &quot;fields&quot;: [
            &quot;name&quot;,
            &quot;author&quot;,
            &quot;title&quot;,
            &quot;webUrl&quot;,
            &quot;size&quot;,
            &quot;id&quot;,
            &quot;Customer&quot;, ... whatever       
        ]
      }   
   ] }
  </code></pre>
  <p>This works fine if I do this for <em>internal users</em>.<br />
  However, if guests are added via Azure B2B collaboration to our SharePoint, they cannot access this endpoint, even though the tokens contain the same scopes (Sites.ReadWrite.All Files.ReadWrite.All...)</p>
  <p>Graph returns an error message instead a list of files:</p>
  <blockquote>
  <p>{
  &quot;error&quot;: {
  &quot;code&quot;: &quot;System.UnauthorizedAccessException&quot;,
  &quot;message&quot;: &quot;\r\n The service is not authorized for provided user credentials&quot;,
  &quot;target&quot;: &quot;&quot;,
  &quot;level&quot;: &quot;Error&quot;
  },
  &quot;instrumentation&quot;: {
  &quot;traceId&quot;: &quot;97d66c34-9643-a0ec-1d08-52d2bc49ab5a&quot;
  }
  }</p>
  </blockquote>
  <p>If I search for &quot;The service is not authorized for provided user credentials&quot; in Google I do not find a single result.<br />
  The classical REST endpoint of SharePoint works for them, but I want to upgrade to graph.<br />
  Any ideas?</p>