title: Resource <Random Guid> does not exist or one of its queried reference-property objects are not present
body: <p>I'm trying to do a basic call into Microsft Graph.</p>
  
  <p><a href="https://graph.microsoft.com/v1.0/me/" rel="noreferrer">https://graph.microsoft.com/v1.0/me/</a></p>
  
  <p>I've done this through the C# SDK and directly using rest and on both calls, I'm getting the following error</p>
  
  <p>Message = "Resource 'f9d58168-4b3e-4948-9133-6c978d1ab18a' does not exist or one of its queried reference-property objects are not present."</p>
  
  <p><strong>Full error message returned in error response content stream</strong></p>
  
  <pre><code>{
    "error": {
      "code": "Request_ResourceNotFound",
      "message": "Resource 'f9d58168-4b3e-4948-9133-6c978d1ab18a' does not exist or one of its queried reference-property objects are not present.",
      "innerError": {
        "request-id": "80af6aec-5052-49ab-890c-273fea5c65ba",
        "date": "2017-07-31T06:08:37"
      }
    }
  }
  </code></pre>
  
  <p>The GUID can be different.</p>
  
  <p>When I do this through the Graph Explorer it works OK.</p>
  
  <p>This is the code I'm using to get the credentials for the App</p>
  
  <pre><code>private ClientCredential GetCredentials()
  {
    return new ClientCredential(_azureAdOptions.ClientId, _azureAdOptions.ClientSecret);
  }
  
  private AuthenticationContext GetContext(string userObjectId)
  {
    return new AuthenticationContext($"{_azureAdOptions.AadInstance}{_azureAdOptions.Tenant}", GetTokenCache(userObjectId));
  }
  
  private DistributedTokenCache GetTokenCache(string userObjectId)
  {
    return new DistributedTokenCache(userObjectId, _azureAdOptions.ClientId, _distributedCache, _loggerFactory);
  }
  
  public async Task&lt;AuthenticationResult&gt; GetToken(string userObjectId, string resourceId)
          {
              AuthenticationResult result;
  
              var authContext = GetContext(userObjectId);
              var credential = GetCredentials();
  
              try
              {
                  result = await authContext.AcquireTokenSilentAsync(resourceId, credential, new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));
              }
              catch (AdalSilentTokenAcquisitionException astae)
              {
                  result = await authContext.AcquireTokenAsync(resourceId, credential);
              }
  
              return result;
          }
  </code></pre>
  
  <p>I've debugged through the code and it's authenticating and acquiring a token OK.</p>
  
  <p>Have copied and pasted the Request URL from my App into the Graph Explorer and it works.</p>
  
  <p>Have setup permissions through Azure and they are the same as the ones setup for Graph Explorer.</p>
  
  <p>This is the configuration I'm using in StartUp to setup OpenId </p>
  
  <pre><code>var openIdConnectOptions = new OpenIdConnectOptions
              {
                  ClientId = azureAdOptions.ClientId,
                  Scope =
                  {
                      "openid",
                      "email",
                      "profile",
                      "offline_access",
                      "User.Read",
                      "user_impersonation"
                  },
                  Authority = $"{azureAdOptions.AadInstance}{azureAdOptions.Tenant}",
                  SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme,
                  AuthenticationScheme = OpenIdConnectDefaults.AuthenticationScheme,
                  PostLogoutRedirectUri = azureAdOptions.PostLogoutRedirectUri,
                  ResponseType = OpenIdConnectResponseType.CodeIdToken,
                  UseTokenLifetime = true,
                  GetClaimsFromUserInfoEndpoint = false,
                  Events = new OpenIdConnectEvents
                  {
                      OnRedirectToIdentityProvider = OnRedirectToIdentityProvider,
                      OnRemoteFailure = OnAuthenticationFailed,
                      OnAuthorizationCodeReceived = OnAuthorizationCodeReceived,
                      OnUserInformationReceived = OnUserInformationReceived
                  }
              };
  </code></pre>
  
  <p>I'm using the code in a differnt application that calls Microsoft Graph and have not had any problems with that.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I was able to get the User ID from the claims principal (<a href="http://schemas.microsoft.com/identity/claims/objectidentifier" rel="noreferrer">http://schemas.microsoft.com/identity/claims/objectidentifier</a>) and I used this ID to call "<a href="https://graph.microsoft.com/v1.0/users" rel="noreferrer">https://graph.microsoft.com/v1.0/users</a>('') with the same error. The GUID in the error message is the GUID of the user from the claims principal.</p>
  
  <p>So why is the user ID in the claims principal not being set correctly?</p>
  
  <p><strong>FURTHER UPDATE</strong></p>
  
  <p>It looks like the object identifier set in the Claims Principal is different to the one in Azure Active directory.</p>
  
  <p>Hard coding the object identifier into the users endpoint works.</p>
  
  <p><strong>FURTHER FURTHER UPDATE</strong></p>
  
  <p>This seems to be something to do with the access token that is being returned. After decrypting the token I can see the Object ID is that of the registered application and this is what is being used when calling "Me" in the Office Graph. Shouldn't the OID of the token being returned be of the user. The app has User.Read in Active Directory.</p>
  
  <p><strong>ERROR BEING RETURNED BY AcquireTokenSilentAsync</strong></p>
  
  <pre><code>Microsoft.IdentityModel.Clients.ActiveDirectory.AdalSilentTokenAcquisitionException:
     at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenSilentHandler.SendTokenRequestAsync (Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.1.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35: c:\workspace\azure-activedirectory-library-for-dotnet-v3-master-VS2017\src\ADAL.PCL\Flows\AcquireTokenSilentHandler.cs: 61)
     at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase+&lt;RunAsync&gt;d__55.MoveNext (Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.1.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35: c:\workspace\azure-activedirectory-library-for-dotnet-v3-master-VS2017\src\ADAL.PCL\Flows\AcquireTokenHandlerBase.cs: 198)
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
     at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext+&lt;AcquireTokenSilentCommonAsync&gt;d__55.MoveNext (Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.1.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35: c:\workspace\azure-activedirectory-library-for-dotnet-v3-master-VS2017\src\ADAL.PCL\AuthenticationContext.cs: 618)
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
     at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext+&lt;AcquireTokenSilentAsync&gt;d__41.MoveNext (Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.1.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35: c:\workspace\azure-activedirectory-library-for-dotnet-v3-master-VS2017\src\ADAL.PCL\AuthenticationContext.cs: 415)
     at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
     at InSite.Security.AuthenticationService+&lt;GetToken&gt;d__5.MoveNext (InSite.Security, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null: C:\Users\TobyStatham\Documents\Visual Studio 2017\Projects\InSite\InSite.Security\AuthenticationService.cs: 47)
  </code></pre>