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

Allow user to override which interactive authentication flow used for MS auth #212

Merged
merged 2 commits into from
Nov 9, 2020

Conversation

mjcheetham
Copy link
Collaborator

Allow the user to override which Microsoft authentication flow to use when interaction is required.

The options available are:

  • embedded web view
  • system web view
  • device code

Previously we always picked one of these flows (or used a native external helper) to use. In some instances it may be desirable for the user to force a particular flow, for instance to take advantage of browser sign-in state or OS integrations by using 'system'.

If no option is set, or auto is selected the existing behaviour is preserved (we pick for the user).

Fixes #210

@mjcheetham mjcheetham added enhancement New feature or request auth:microsoft Specific to Microsoft AAD/MSA authentication labels Nov 6, 2020
Comment on lines +133 to +141
case MicrosoftAuthenticationFlowType.Auto:
if (CanUseEmbeddedWebView())
goto case MicrosoftAuthenticationFlowType.EmbeddedWebView;

if (CanUseSystemWebView(app, redirectUri))
goto case MicrosoftAuthenticationFlowType.SystemWebView;

// Fall back to device code flow
goto case MicrosoftAuthenticationFlowType.DeviceCode;
Copy link
Contributor

Choose a reason for hiding this comment

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

The existence of gotos makes me want to restructure this code. However, this switch is so carefully constructed, that the alternatives actually look worse. Kudos on finding a good use for goto.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, this sort of "have several options, and an 'auto' choice that may pick one of those options" pattern is best served with a switch with goto case, IMO.
It's the only time I've found goto is acceptable; plus goto case feels safer that a random label.

This same pattern is already present in the GitHubAuthentication class for selecting the type of auth flow (user/pass or OAuth) or letting it auto-detect.

Allow the user to override which Microsoft authentication flow to use
when interaction is required.

The options available are:
 - embedded web view
 - system web view
 - device code

Previously we always picked one of these flows (or used a native
external helper) to use. In some instances it may be desirable for the
user to force a particular flow, for instance to take advantage of
browser sign-in state or OS integrations by using 'system'.

If no option is set, or `auto` is selected the existing behaviour is
preserved (we pick for the user).
Use the localhost redirect URI specified in the VS AAD application
configuration. The localhost option allows us to use the system web
view, whereas 'urn:ieft:wg:oauth:2.0:oob' does not.
@mjcheetham mjcheetham merged commit df90676 into git-ecosystem:master Nov 9, 2020
@mjcheetham mjcheetham deleted the msauth-choice branch November 9, 2020 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth:microsoft Specific to Microsoft AAD/MSA authentication enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide options to override MS authentication flows
2 participants