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

Add Audience as an alias to TenantId. #728

Merged
merged 3 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Authentication/Authentication.Core/Authenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static async Task<IAuthContext> AuthenticateAsync(IAuthContext authContex
{
authContext.AuthProviderType = AuthProviderType.DeviceCodeProviderFallBack;
fallBackWarning?.Invoke();
var fallBackAuthContext= await AuthenticateAsync(authContext, forceRefresh, cancellationToken, fallBackWarning);
var fallBackAuthContext = await AuthenticateAsync(authContext, forceRefresh, cancellationToken, fallBackWarning);
return fallBackAuthContext;
}
break;
Expand Down Expand Up @@ -111,12 +111,23 @@ public static async Task<IAuthContext> AuthenticateAsync(IAuthContext authContex
}
return fallBackAuthContext;
}
// DeviceCode Authentication Failure: Timeout

if (authEx.InnerException is TaskCanceledException && cancellationToken.IsCancellationRequested)
{
// DeviceCodeTimeout
// Authentication requets timeout.
throw new Exception(string.Format(CultureInfo.CurrentCulture, ErrorConstants.Message.DeviceCodeTimeout, Constants.MaxDeviceCodeTimeOut));
}
else if (authEx.InnerException is MsalServiceException msalServiceEx
&& msalServiceEx.StatusCode == 400
&& msalServiceEx.ErrorCode == "invalid_scope"
&& string.IsNullOrWhiteSpace(authContext.TenantId)
&& (authContext.AuthProviderType == AuthProviderType.DeviceCodeProvider
|| authContext.AuthProviderType == AuthProviderType.DeviceCodeProviderFallBack))
{
// MSAL scope validation error. Ask customer to specify sign-in audience or tenant Id.
throw new MsalClientException(msalServiceEx.ErrorCode, $"{msalServiceEx.Message}.\r\n{ErrorConstants.Message.InvalidScope}", msalServiceEx);
}

//Something Unknown Went Wrong
throw authEx.InnerException ?? authEx;
}
Expand Down
1 change: 1 addition & 0 deletions src/Authentication/Authentication.Core/ErrorConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static class Message
{
public const string MissingAuthContext = "Authentication needed, call Connect-MgGraph.";
internal const string InvalidJWT = "Invalid JWT access token.";
internal const string InvalidScope = "Please retry by specifying a sign-in -Audience or -TenantId to Connect-MgGraph. e.g., Connect-MgGraph -Audience 'organizations' -Scopes 'YOUR_SCOPES' -UseDeviceAuthentication.";
internal const string NullOrEmptyParameter = "Parameter '{0}' cannot be null or empty.";
internal const string MacKeyChainFailed = "{0} failed with result code {1}.";
internal const string DeviceCodeTimeout = "Device code terminal timed-out after {0} seconds. Please try again.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public class ConnectMgGraph : PSCmdlet, IModuleAssemblyInitializer, IModuleAssem
[Parameter(ParameterSetName = Constants.AppParameterSet)]
[Parameter(ParameterSetName = Constants.UserParameterSet,
Position = 4,
HelpMessage = "The id of the tenant to connect to.")]
HelpMessage = "The id of the tenant to connect to. You can also use this parameter to specify your sign-in audience. i.e., common, organizations, or consumers. " +
"See https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-client-application-configuration#authority.")]
[Alias("Audience")]
public string TenantId { get; set; }

[Parameter(ParameterSetName = Constants.AppParameterSet)]
Expand Down