Forum Discussion

OreSpurt's avatar
OreSpurt
Copper Contributor
Apr 11, 2023

Base URL used for Multi Tenants

Hello,

I want users to select files from their personal and company drive but it requires a base url which is used to authenticate the user into the drive but the code examples and the docs don't have any indication of where to get a dynamic base url or the base url to use for the multiple tenants. 

 

Right now it only works for users in my organisation but I need it for users.

 

Edit: I am using the v8 file picker

 

Thank you

  • mgouker's avatar
    mgouker
    Copper Contributor
    It's been a while since this was posted but you may have a simple problem to solve. Change your msalConfig to include common to support multitenant. Something like this:

    const msalConfig = {
    auth: {
    // 'Application (client) ID' of app registration in Azure portal - this value is a GUID
    clientId: "b9c6e65c-cbf5-4ffb-998f-6b1114440a93",
    // Full directory URL, multi-tenant application. (MUST be /common)
    authority: "https://login.microsoftonline.com/common",
    // Full redirect URL
    redirectUri: your_server_name, // <--- same as in the app registration in azure.
    },
    • Tornado_339's avatar
      Tornado_339
      Copper Contributor

      I am facing the same issue. I am integrating the file picker in my website for multi tenants app but don't have generic baseUrl for picker. Sample code given by Microsoft has suggested to use hard coded value for baseUrl for testing which will work for single tenant app but no mention of how to replace this for multi tenant app. Documentation and Sample code . (Note: I have already changed my msalConfig as suggested by mgouker). And For personal account baseUrl - https://onedrive.live.com/picker is not working 

      const url = combine(
      baseUrl,
      `/_layouts/15/FilePicker.aspx?${queryString}`
      );

      • AlexD775's avatar
        AlexD775
        Copper Contributor
        I have the exact same issue. The documentation for the v8 file picker is extremely frustrating because it leaves out major steps for common cases, e.g. this multitenant case. That is, I want to be able to set up my Application so that business users (from ANY tenant) can log in to their MS accounts using OAuth, then I can launch the filepicker control to allow the user to choose their files.

        I have everything working with single tenant and consumer accounts. With business accounts, I am correctly launching the OAuth dialog using the authority of `https://login.microsoftonline.com/common`. However, from there I need to know the user's tenant to use as the baseUrl for opening the FilePicker (as Tornado_339 mentioned) and there is no doc on how to do that. In addition, there are some settings in the picker config that expect tenant-scoped values, and it's not at all clear how to get these. I think I'm making more progress reverse engineering the OneDrive picker config as integrated with ChatGPT than I am trying to find any docs from Microsoft on this issue.
  • NikolinoDE's avatar
    NikolinoDE
    Gold Contributor

    OreSpurt 

    It sounds like you are trying to use the Microsoft OneDrive for Business API to allow users to select files from their personal and company drives.

    To authenticate users from multiple tenants, you will need to use the OAuth 2.0 protocol and obtain authorization credentials for each user.

    The base URL for the OAuth 2.0 server is https://login.microsoftonline.com/common/oauth2/v2.0/authorize.

    You can use this URL to redirect users to the Microsoft authorization server where they can grant your application access to their OneDrive data.

    Once the user has granted access, you will receive an authorization code that you can exchange for an access token and a refresh token.

    You can then use the access token to make authorized API requests on behalf of the user.

    For more information on how to implement OAuth 2.0 for multiple tenants with OneDrive for Business, please refer to the Microsoft Graph documentation.

     

    I hope this helps!

Resources