@@ -35,7 +35,8 @@ public MicrosoftAuthentication(ICommandContext context)
35
35
public async Task < JsonWebToken > GetAccessTokenAsync (
36
36
string authority , string clientId , Uri redirectUri , string resource , Uri remoteUri , string userName )
37
37
{
38
- // If we find an external authentication helper we should delegate everything to it
38
+ // If we find an external authentication helper we should delegate everything to it.
39
+ // Assume the external helper can provide the best authentication experience.
39
40
if ( TryFindHelperExecutablePath ( out string helperPath ) )
40
41
{
41
42
return await GetAccessTokenViaHelperAsync ( helperPath ,
@@ -51,6 +52,9 @@ public async Task<JsonWebToken> GetAccessTokenAsync(
51
52
52
53
#region Authentication strategies
53
54
55
+ /// <summary>
56
+ /// Start an authentication helper process to obtain an access token.
57
+ /// </summary>
54
58
private async Task < JsonWebToken > GetAccessTokenViaHelperAsync ( string helperPath ,
55
59
string authority , string clientId , Uri redirectUri , string resource , Uri remoteUri , string userName )
56
60
{
@@ -74,6 +78,9 @@ private async Task<JsonWebToken> GetAccessTokenViaHelperAsync(string helperPath,
74
78
return new JsonWebToken ( accessToken ) ;
75
79
}
76
80
81
+ /// <summary>
82
+ /// Obtain an access token using MSAL running inside the current process.
83
+ /// </summary>
77
84
private async Task < JsonWebToken > GetAccessTokenInProcAsync ( string authority , string clientId , Uri redirectUri , string [ ] scopes , string userName )
78
85
{
79
86
IPublicClientApplication app = await CreatePublicClientApplicationAsync ( authority , clientId , redirectUri ) ;
@@ -86,12 +93,28 @@ private async Task<JsonWebToken> GetAccessTokenInProcAsync(string authority, str
86
93
result = await GetAccessTokenSilentlyAsync ( app , scopes , userName ) ;
87
94
}
88
95
96
+ //
89
97
// If we failed to acquire an AT silently (either because we don't have an existing user, or the user's RT has expired)
90
98
// we need to prompt the user for credentials.
91
- // Depending on the current platform and session type we try to show the most appropriate authentication interface.
99
+ //
100
+ // Depending on the current platform and session type we try to show the most appropriate authentication interface:
101
+ //
102
+ // On .NET Framework MSAL supports the WinForms based 'embedded' webview UI. For Windows + .NET Framework this is the
103
+ // best and natural experience.
104
+ //
105
+ // On other runtimes (e.g., .NET Core) MSAL only supports the system webview flow (launch the user's browser),
106
+ // and the device-code flows.
107
+ //
108
+ // Note: .NET Core 3 allows using WinForms when run on Windows but MSAL does not yet support this.
109
+ //
110
+ // The system webview flow requires that the redirect URI is a loopback address, and that we are in an interactive session.
111
+ //
112
+ // The device code flow has no limitations other than a way to communicate to the user the code required to authenticate.
113
+ //
92
114
if ( result is null )
93
115
{
94
116
#if NETFRAMEWORK
117
+ // If we're in an interactive session and on .NET Framework, let MSAL show the WinForms-based embeded UI
95
118
if ( PlatformUtils . IsInteractiveSession ( ) )
96
119
{
97
120
result = await app . AcquireTokenInteractive ( scopes )
@@ -121,6 +144,9 @@ private async Task<JsonWebToken> GetAccessTokenInProcAsync(string authority, str
121
144
return new JsonWebToken ( result . AccessToken ) ;
122
145
}
123
146
147
+ /// <summary>
148
+ /// Obtain an access token without showing UI or prompts.
149
+ /// </summary>
124
150
private async Task < AuthenticationResult > GetAccessTokenSilentlyAsync ( IPublicClientApplication app , string [ ] scopes , string userName )
125
151
{
126
152
try
0 commit comments