'MS Azure App - Cross organisation (Multi Tenant) access to Sharepoint files

Required: MS Graph App that has access to companyB.sharepoint.com drive/file items for a member of CompanyA

I am from Company/Organisation A. I have been granted access to a sharepoint site of Company/Orgtanisation B. https://companyB.sharepoint.com/sites/company_name/XXXX%20Files/Forms/AllItems.aspx

Via a browser this works as expected (i.e. access to the sharepoint site)

I have created a Multi-Tenant App (Azure dev portal) and have been able to receive a user delegated access token. refresh token works fine. The App (Overview) => Supported Account types: Multiple organisations.

Using the Graph Explorer (Authenticated for company A user) https://developer.microsoft.com/en-us/graph/graph-explorer

https://graph.microsoft.com/v1.0/sites/companyB.sharepoint.com:/sites returns

{
"error": {
    "code": "invalidRequest",
    "message": "Invalid hostname for this tenancy",
    "innerError": {
        "date": "2022-04-12T04:36:00",
        "request-id": "qqq21a6d3-xxx-xxx-xxx-xxx390a4yyy",
        "client-request-id": "qqq382fa-xxx-xxx-xxx-xxx708yyy"
    }
}

}

What I'm trying to achieve is to get access to and obtain a list of files contained in the Sharepoint site under CompanyB. Then being able to walk through the files, add/edit/delete files to these directories (or whatever terminology MS uses for Sites and Files/Folders within a site) I cannot seem to find the 'SiteID' or 'DriveId' that the URL references point to...

Would it be feasible to create an APP under Company B (ie create a dev account for them) and create a simpler, non verified, organisation only app under company B and then login as a user from Company A?

Any pointers of examples of anyone that has done this is appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source