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
14 changes: 12 additions & 2 deletions src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ namespace Microsoft.Graph.PowerShell.Authentication.Cmdlets
using System.Linq;
using System.Management.Automation;
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using System.Threading.Tasks;

using Microsoft.Graph.Authentication.Core;
using Microsoft.Graph.PowerShell.Authentication.Common;
using Microsoft.Graph.PowerShell.Authentication.Extensions;
using Microsoft.Graph.PowerShell.Authentication.Helpers;
using Microsoft.Graph.PowerShell.Authentication.Interfaces;
using Microsoft.Graph.PowerShell.Authentication.Models;
Expand Down Expand Up @@ -189,8 +191,16 @@ private async Task ProcessRecordAsync()
authContext.AuthType = AuthenticationType.Delegated;
string[] processedScopes = ProcessScopes(Scopes);
authContext.Scopes = processedScopes.Length == 0 ? new[] { "User.Read" } : processedScopes;
// Default to CurrentUser but allow the customer to change this via `ContextScope` param.
authContext.ContextScope = this.IsParameterBound(nameof(ContextScope)) ? ContextScope : ContextScope.CurrentUser;
if (RuntimeInformation.OSDescription.ContainsValue("WSL", StringComparison.InvariantCulture))
{
// Use process scope when on WSL. WSL does not have secret service that the we use to cache tokens on Linux, see https://github.com/microsoft/WSL/issues/4254.
authContext.ContextScope = ContextScope.Process;
}
else
{
// Default to CurrentUser but allow the customer to change this via `ContextScope` param.
authContext.ContextScope = this.IsParameterBound(nameof(ContextScope)) ? ContextScope : ContextScope.CurrentUser;
}
authContext.AuthProviderType = UseDeviceAuthentication ? AuthProviderType.DeviceCodeProvider : AuthProviderType.InteractiveAuthenticationProvider;
if (!string.IsNullOrWhiteSpace(ClientId))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Authentication/Authentication/Common/DiskDataStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ public string[] GetDirectories(string startDirectory, string filePattern, Search
/// <returns>A <see cref="FileStream"/> to the specified path with shared read.</returns>
public Stream OpenForSharedRead(string path)
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
return File.Open(path, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read);
}

Expand All @@ -223,8 +224,7 @@ public Stream OpenForSharedRead(string path)
/// <returns>A <see cref="FileStream"/> to the specified path with exclusive write.</returns>
public Stream OpenForExclusiveWrite(string path)
{
string directory = Path.GetDirectoryName(path);
Directory.CreateDirectory(directory);
Directory.CreateDirectory(Path.GetDirectoryName(path));
return File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
}
}
Expand Down