CommunityToolkit / Graph-Controls

Set of Helpers and Controls for Windows development using the Microsoft Graph.
https://docs.microsoft.com/en-us/windows/communitytoolkit/graph/overview
Other
155 stars 39 forks source link

Added scopes parameter to IProvider.GetTokenAsync #113

Closed shweaver-MSFT closed 3 years ago

shweaver-MSFT commented 3 years ago

Fixes #111

PR Type

What kind of change does this PR introduce?

What is the current behavior?

Currently, there is no way to request an access token for scopes that were not initially requested during provider construction. This limits the ability to adopt Graph APIs over time, as features are introduced.

// In app startup code:
// The provider is constructed with an initial set of scopes.
string[] initialScopes = new string[] { "User.Read" };
ProviderManager.Instance.GlobalProvider = new WindowsProvider(initialScopes);

// Somewhere else in the app:
// GetTokenAsync can only retrieve a token configured for the scopes created during provider construction.
IProvider provider = ProviderManager.Instance.GlobalProvider;
string token = await provider.GetTokenAsync(silentOnly: false);

What is the new behavior?

The new behavior adds an additional string[] scopes = null parameter to the end of GetTokenAsync. This allows the option of providing a specific set of scopes to request in the access token:

// App startup code, same as before.

// Somewhere else in the app:
// Alternate scopes can now be requested ad hoc.
IProvider provider = ProviderManager.Instance.GlobalProvider;
string[] alternateScopes = new string[] { "Tasks.ReadWrite", "People.Read" };
string token = await provider.GetTokenAsync(false, alternateScopes);

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

ghost commented 3 years ago

Thanks shweaver-MSFT for opening a Pull Request! The reviewers will test the PR and highlight if there is any merge conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌