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

Add overload of GetTokenAsync with an exception out param #196

Open asklar opened 2 years ago

asklar commented 2 years ago

PR Type

What kind of change does this PR introduce?

What is the current behavior?

The WCT MsalProvider doesn't expose exceptions returned from the MSAL library. You can see that a token returned is null, but the information about what went wrong is lost.

What is the new behavior?

New overload (since the previous methods come from a base class and didn't want to touch that), for GetTokenAsync that can return out the exception that we encountered.

PR Checklist

Other information

ghost commented 2 years ago

Thanks asklar 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 🙌

michael-hawker commented 1 year ago

Thanks @asklar,

I'm not sure how a non-default out parameter for a method works after a parameter with a default value @Sergio0694?

Since the method is protected, this will break someone if they've inherited from this class, eh?

protected async Task<string> GetTokenWithScopesAsync(string[] scopes, bool silentOnly = false, out Exception exception)

And since the exception is now re-thrown, even though it wasn't good that we ate the exception, it does mean the code would now cause a consuming application to crash instead now.

ExceptionDispatchInfo.Capture(exception).Throw();

Think we may want to just make a larger breaking change here to clean this up in the future?

@Richasy what are your thoughts as well? Think we'll skip this one for the 7.1.3 patch?

michael-hawker commented 1 year ago

This also ties into #180