Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
// ------------------------------------------------------------------------------
using Azure.Core;
using Azure.Core.Diagnostics;
using Azure.Identity;
using Microsoft.Graph.PowerShell.Authentication.Core.Extensions;
using Microsoft.Identity.Client;
using Microsoft.Identity.Client.Extensions.Msal;
using System;
using System.Diagnostics.Tracing;
using System.Globalization;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -201,8 +203,14 @@ public static async Task<IAuthContext> AuthenticateAsync(IAuthContext authContex
{
try
{
signInAuthContext = await SignInAsync(authContext, cancellationToken).ConfigureAwait(false);
retrySignIn = false;
// Write MSAL logs to debug stream.
using (AzureEventSourceListener listener = new AzureEventSourceListener(
(args, message) => GraphSession.Instance.OutputWriter.WriteDebug($"{message}"),
level: EventLevel.Informational))
{
signInAuthContext = await SignInAsync(authContext, cancellationToken).ConfigureAwait(false);
retrySignIn = false;
};
}
catch (AuthenticationFailedException authEx)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,17 @@ Describe 'Connect-MgGraph In App Mode' {
}

}

Describe 'Connect-MgGraph Dependency Resolution' {
It 'Should load Mg module side by side with Az module.' {
{ Connect-AzAccount -ApplicationId $RandomClientId -CertificateThumbprint "Invalid" -Tenant "Invalid" -ErrorAction Stop } | Should -Throw -ExpectedMessage "*Could not find tenant id*"
{ Connect-MgGraph -TenantId "thisdomaindoesnotexist.com" -ErrorAction Stop -UseDeviceAuthentication } | Should -Throw -ExpectedMessage "*AADSTS90002*"
}
}

Describe 'Connect-MgGraph Logging' {
It 'Should write MSAL logs to debug stream.' {
$MgDebugStream = $(Connect-MgGraph -TenantId "thisdomaindoesnotexist.com" -UseDeviceAuthentication -Debug -ErrorAction SilentlyContinue) 5>&1
$MgDebugStream[0] | Should -Match "DeviceCodeCredential.Authenticate invoked. Scopes: \[ User.Read \]"
}
}