how to resolve a user's baseURL for sharepoint for filepicker

Jonathon Love 1 Reputation point
2022-11-05T05:25:10.853+00:00

hi,

we would like to provide the ability for user's to open files from their onedrive/sharepoint in our web application.

i have got the following example working:

https://github.com/OneDrive/samples/tree/master/samples/file-picking/javascript-basic

however, the example requires you to provide the baseUrl for the user who is going to be interacting. that's fine for testing purposes, i can just enter the baseUrl that corresponds to my organisation ... i.e. https://xxxxxxx-my.sharepoint.com

however, this clearly won't work for anyone not in my organization. what is the correct way to do this, that will let anyone (irrespective of their organization) open files from the sharepoints they have access to?

i wondered if i'd find the user's sharepoint address somewhere inside https://graph.microsoft.com/v1.0/me but this doesn't seem to be the case.

ideally there'd be a way to determine whether the user preferred to use onedrive or sharepoint, and a way to resolve the correct url.

anyone have any ideas?

with thanks

SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,754 questions
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 32,476 Reputation points Microsoft Vendor
    2022-11-07T02:47:55.31+00:00

    Hi @Jonathon Love
    You need to create a AAD App Registration to authentication file picker. You can see to required setup in the document

    Create a new AAD App Registration, note the ID of the application
    Under authentication, create a new Single-page application registry
    Set the redirect uri to https://localhost (this is for testing the samples)
    Ensure both Access tokens and ID tokens are checked
    You may optionally configure this application for multitenant but this is outside the scope of this article
    Under API permissions
    Add Files.Read.All, Sites.Read.All, Leave User.Read for Graph delegated permissions
    Add AllSites.Read, MyFiles.Read for SharePoint delegated permissions

    For more details, please refer to the document
    https://learn.microsoft.com/en-us/onedrive/developer/controls/file-pickers/?view=odsp-graph-online


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.