Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for GCC and other sovereign clouds #1928

Merged
merged 28 commits into from
Dec 6, 2022

Conversation

musale
Copy link
Contributor

@musale musale commented Nov 2, 2022

Closes #1030

PR Type

  • Feature

Description of the changes

PR checklist

  • License header has been added to all new source files (yarn setLicense)
  • Contains NO breaking changes

Other information

You can set the baseURL when initializing your provider like this:

Usage

This sets the baseUrl for the MSAL2Provider, MsalProvider, TeamsMsalProvider and TeamsMsal2Provider .

<mgt-msal2-provider
      client-id="2dfea037-938a-4ed8-9b35-c05708a1b241"
      redirect-uri="http://localhost:3000"
      base-url="https://dod-graph.microsoft.us"
      scopes="user.read,user.read.all">
</mgt-msal2-provider>

<mgt-msal-provider
      client-id="2dfea037-938a-4ed8-9b35-c05708a1b241"
      redirect-uri="http://localhost:3000"
      base-url="https://dod-graph.microsoft.us"
      scopes="user.read,user.read.all">
</mgt-msal-provider>

In Teams, you have to call handleAuth first to handle all client side auth or permission consent.

<html>
  <head>
    <script src="https://unpkg.com/@microsoft/teams-js/dist/MicrosoftTeams.min.js" crossorigin="anonymous"></script>
    <script>
      mgt.TeamsProvider.handleAuth(baseUrl="https://dod-graph.microsoft.us");
    </script> -->
    <script type="module">
      // import { TeamsProvider } from './packages/providers/mgt-teams-provider/dist/es6/TeamsProvider.js';
      // TeamsProvider.handleAuth();

      import { TeamsMsal2Provider } from './packages/providers/mgt-teams-msal2-provider/dist/es6/TeamsMsal2Provider.js';
      TeamsMsal2Provider.handleAuth(baseUrl="https://dod-graph.microsoft.us");
    </script>
  </head>
  <body>
    Signing You In...
  </body>
</html>

<mgt-teams-msal2-provider
      client-id="2dfea037-938a-4ed8-9b35-c05708a1b241"
      redirect-uri="http://localhost:3000"
      base-url="https://dod-graph.microsoft.us"
      scopes="user.read,user.read.all">
</mgt-teams-msal2-provider>

<mgt-teams-msal-provider
      client-id="2dfea037-938a-4ed8-9b35-c05708a1b241"
      redirect-uri="http://localhost:3000"
      base-url="https://dod-graph.microsoft.us"
      scopes="user.read,user.read.all">
</mgt-teams-msal2-provider>

This sets the baseURL for ElectronProvider

import { ElectronProvider } from '@microsoft/mgt-electron-provider';
Providers.globalProvider = new ElectronProvider(baseUrl="https://dod-graph.microsoft.us");

This sets the baseURL for SharePointProvider

import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';

// import the providers at the top of the page
import { Providers, SharePointProvider } from '@microsoft/mgt-spfx';

export interface IMgtDemoWebPartProps {
  description: string;
}

export default class MgtDemoWebPart extends BaseClientSideWebPart<IMgtDemoWebPartProps> {
  // set the global provider
  protected async onInit() {
    Providers.globalProvider = new SharePointProvider(this.context, baseUrl="https://dod-graph.microsoft.us");
  }
// Rest of the code

base-url specifies a base url for the graph client config. It is optional and defaults to https://graph.microsoft.com.

With this attribute, you can pass in any of the GCC and national clouds urls
@musale musale added this to the v3.0.0 milestone Nov 2, 2022
@ghost
Copy link

ghost commented Nov 2, 2022

Thank you for creating a Pull Request @musale.

This is a checklist for the PR reviewer(s) to complete before approving and merging this PR:

  • I have verified a documentation PR has been linked and is approved (or not applicable)
  • I have ran this PR locally and have tested the fix/feature
  • I have verified that stories have been added to storybook (or not applicable)
  • I have tested existing stories in storybook to verify no regression has occured
  • I have tested the solution in at least two browsers (Edge + 1 non-Chromium based browser)

@sebastienlevert
Copy link
Contributor

Would love to see in the PR some of the usage on different providers. Probably via the packages README?

@ghost ghost added Needs: Author Feedback Issue needs response from issue author and removed Needs: Author Feedback Issue needs response from issue author labels Nov 2, 2022
@musale
Copy link
Contributor Author

musale commented Nov 3, 2022

Would love to see in the PR some of the usage on different providers. Probably via the packages README?

Yes! I'm doing incremental updates per provider BUT on this same PR. The final result is all providers supporting the approach and fully documented in all the relevant places.

@gavinbarron gavinbarron linked an issue Nov 8, 2022 that may be closed by this pull request
@musale musale marked this pull request as ready for review November 14, 2022 11:29
Copy link
Member

@gavinbarron gavinbarron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite clear why we're doing so much repeated work in each of the providers and not pushing that work to the base classes.

packages/mgt-element/src/providers/IProvider.ts Outdated Show resolved Hide resolved
@musale
Copy link
Contributor Author

musale commented Nov 15, 2022

I'm not quite clear why we're doing so much repeated work in each of the providers and not pushing that work to the base classes.

Oh my! That completely escaped my refactors. Let me mop up and hopefully reduce the changes.

@sebastienlevert sebastienlevert removed this from the v3.0.0 milestone Nov 29, 2022
@ghost ghost added the Needs: Author Feedback Issue needs response from issue author label Nov 29, 2022
@ghost ghost removed the Needs: Author Feedback Issue needs response from issue author label Dec 2, 2022
@sebastienlevert sebastienlevert merged commit 1edf635 into next/fluentui Dec 6, 2022
@sebastienlevert sebastienlevert deleted the musale/support-gcc branch December 6, 2022 16:30
Mnickii pushed a commit that referenced this pull request Dec 15, 2022
* feat: add support for configuring the base URL in the graph client

* feat: add base-url attribute to Msal2Provider

base-url specifies a base url for the graph client config. It is optional and defaults to https://graph.microsoft.com.

With this attribute, you can pass in any of the GCC and national clouds urls

* refactor: use GraphEndpoint type instead of string

* refactor: move validating base URL to utility function

* fix: use new URL().origin to validate the base URL

* feat: set baseURL when you initialize with clientID

* feat: update the types on the declared variable

* fix: cast string to GraphEndpoint type in validation

* feat: update MsalProvider to use base-url property

* feat: update the ElectronProvider to set a baseURL

You can set a baseURL when calling the electron provider.

Additional refactors to fix tsc errors

* feat: add base url to Sharepoint provider

* feat: add base-url attribute to TeamsMsal2Provider

Since it uses Msal2Provider, all we do is pass the base URL where Msal2Provider is called

* feat: add base-url attribute to TeamsMsalProvider

Since it uses MsalProvider, all we do is pass the base URL where MsalProvider is called

* feat: add base-url attribute to TeamsFxProvider

The baseUrl is passed during initialization. The default is already set to MICROSOFT_GRAPH_DEFAULT_ENDPOINT

* feat: change to validating the baseUrl before initializing the client

* refactor: set the baseURL default value in constractor

* refactor: set the baseURL default value in constructor

* feat: add base-url to the baseProvider

* refactor: remove re-declaration of property in base class

* fix: validate base URL string in the IProvider

* fix: do the validation when setting the baseURL

* refactor/docs: use one check to get all accounts and document the exported types

* fix: remove duplicate import

* fix: set licence text on all files

* fix: updaet the memberof value of the base provider

Co-authored-by: Gavin Barron <[email protected]>

Co-authored-by: Gavin Barron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Add support for GCC and other clouds
3 participants