Skip to content

Commit 855e817

Browse files
Feat/force wam (#3472)
* feat: force WAM auth for windows users * feat(auth): Provide messages to user regarding WAM on windows support. * Wiring up WriteWarning * Sign parameter set to True in CI * clear messages regarding WAM option deprecation * remove writeDebug as it doesnt exist in context * bump versions to 2.34.0 * fix warning placement to ensure output is initialized --------- Co-authored-by: Gavin Barron (from Dev Box) <[email protected]>
1 parent fa1577d commit 855e817

20 files changed

+45
-25
lines changed

.azure-pipelines/ci-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ parameters:
1313
default: false
1414
- name: Sign
1515
type: boolean
16-
default: false
16+
default: true
1717
- name: InternalFeed
1818
type: string
1919
default: '0985d294-5762-4bc2-a565-161ef349ca3e/PowerShell_V2_Build'

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,15 @@ When it comes to modifying existing cmdlets, we recommend you use [AutoREST dire
2626
## SDK generation
2727

2828
See our [SDK generation steps wiki](https://github.com/microsoftgraph/msgraph-sdk-powershell/wiki/Generation-Process) for more information.
29+
30+
## Debugging the Auth module
31+
32+
* In a terminal run `.\tools\GenerateAuthenticationModule.ps1 -Build -Pack`
33+
* In Visual Studio open the `.\src\Authentication\Authentication.sln` solution
34+
* Start the project in debug mode
35+
* In the newly opened terminal run `pwd` to get the current working directory for the debug session
36+
* Copy the `Microsoft.Graph.Authencation.<version-number>.nupkg` to the working directory for the debug session
37+
* Rename the `.nupkg` file to `.zip`
38+
* Unzip the files to the working directory
39+
* In the working directory run `Import-Module .\Microsoft.Graph.Authentication.psm1`
40+
* Run any cmdlet from the Authentication module to hit your breakpoints

config/ModuleMetadata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
"versions": {
2828
"authentication": {
2929
"prerelease": "",
30-
"version": "2.33.0"
30+
"version": "2.34.0"
3131
},
3232
"beta": {
3333
"prerelease": "",
34-
"version": "2.33.0"
34+
"version": "2.34.0"
3535
},
3636
"v1.0": {
3737
"prerelease": "",
38-
"version": "2.33.0"
38+
"version": "2.34.0"
3939
}
4040
}
4141
}

docs/authentication.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,4 @@ Set-MgGraphOption -EnableLoginByWAM $true
129129
```PowerShell
130130
Set-MgGraphOption -EnableLoginByWAM $false
131131
```
132+
#### Note: Signin by Web Account Manager (WAM) is enabled by default on Windows and cannot be disabled. Setting this option to $False will have no effect on Windows systems.

src/Authentication/Authentication.Core/Interfaces/IPSGraphOutputWriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public interface IPSGraphOutputWriter
66
{
77
Action<string> WriteObject { get; set; }
88
Action<string> WriteDebug { get; set; }
9+
Action<string> WriteWarning { get; set; }
910
Action<Exception, string, int, object> WriteError { get; set; }
1011
Action<object, string> WriteInformation { get; set; }
1112
Action<string> WriteVerbose { get; set; }

src/Authentication/Authentication.Core/Microsoft.Graph.Authentication.Core.csproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<LangVersion>9.0</LangVersion>
55
<TargetFrameworks>netstandard2.0;net6.0;net472</TargetFrameworks>
66
<RootNamespace>Microsoft.Graph.PowerShell.Authentication.Core</RootNamespace>
7-
<Version>2.31.0</Version>
7+
<Version>2.32.0</Version>
88
<!-- Suppress .NET Target Framework Moniker (TFM) Support Build Warnings -->
99
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
1010
</PropertyGroup>
@@ -13,11 +13,11 @@
1313
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
1414
</PropertyGroup>
1515
<ItemGroup>
16-
<PackageReference Include="Azure.Identity" Version="1.13.2" />
17-
<PackageReference Include="Azure.Identity.Broker" Version="1.2.0" />
18-
<PackageReference Include="Microsoft.Graph.Core" Version="3.2.4" />
16+
<PackageReference Include="Azure.Identity" Version="1.17.1" />
17+
<PackageReference Include="Azure.Identity.Broker" Version="1.3.1" />
18+
<PackageReference Include="Microsoft.Graph.Core" Version="3.2.5" />
1919
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
20-
<PackageReference Include="System.Text.Json" Version="8.0.5" />
20+
<PackageReference Include="System.Text.Json" Version="8.0.6" />
2121
</ItemGroup>
2222
<Target Name="CopyFiles" AfterTargets="Build">
2323
<Copy SourceFiles="@(PreLoadAssemblies)" DestinationFolder="$(OutputPath)/publish" />

src/Authentication/Authentication.Core/Utilities/AuthenticationHelpers.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ private static bool IsAuthFlowNotSupported()
8484

8585
private static bool IsWamSupported()
8686
{
87-
return GraphSession.Instance.GraphOption.EnableWAMForMSGraph && SharedUtilities.IsWindowsPlatform();
87+
return SharedUtilities.IsWindowsPlatform();
8888
}
8989

9090
private static async Task<TokenCredential> GetClientSecretCredentialAsync(IAuthContext authContext)
@@ -129,16 +129,13 @@ private static async Task<InteractiveBrowserCredential> GetInteractiveBrowserCre
129129
authRecord = await Task.Run(() =>
130130
{
131131
// Run the thread in MTA.
132+
GraphSession.Instance.OutputWriter.WriteWarning("Note: Sign in by Web Account Manager (WAM) is enabled by default on Windows. If using an embedded terminal, the interactive browser window may be hidden behind other windows.");
132133
return interactiveBrowserCredential.Authenticate(new TokenRequestContext(authContext.Scopes), cancellationToken);
133134
});
134135
}
135136
else
136137
{
137-
authRecord = await Task.Run(() =>
138-
{
139-
// Run the thread in MTA.
140-
return interactiveBrowserCredential.AuthenticateAsync(new TokenRequestContext(authContext.Scopes), cancellationToken);
141-
});
138+
authRecord = await interactiveBrowserCredential.AuthenticateAsync(new TokenRequestContext(authContext.Scopes), cancellationToken);
142139
}
143140
await WriteAuthRecordAsync(authRecord).ConfigureAwait(false);
144141
return interactiveBrowserCredential;

src/Authentication/Authentication.Test/Microsoft.Graph.Authentication.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>net8.0;net472</TargetFrameworks>
44
<IsPackable>false</IsPackable>
5-
<Version>2.25.0</Version>
5+
<Version>2.32.0</Version>
66
</PropertyGroup>
77
<ItemGroup>
88
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />

src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ private static string GetWelcomeMessage(string clientId, string authType)
275275
stringBuilder.AppendLine($"SDK Docs: {Constants.SdkDocsLink}");
276276
stringBuilder.AppendLine($"API Docs: {Constants.ApiDocsLink}{System.Environment.NewLine}");
277277
stringBuilder.AppendLine($"NOTE: You can use the -NoWelcome parameter to suppress this message.");
278+
stringBuilder.AppendLine($"NOTE: Sign in by Web Account Manager (WAM) is enabled by default on Windows systems and cannot be disabled. Any setting stating otherwise will be ignored.");
278279
return stringBuilder.ToString();
279280
}
280281

src/Authentication/Authentication/Cmdlets/SetMgGraphOption.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ protected override void ProcessRecord()
2525
if (this.IsParameterBound(nameof(EnableLoginByWAM)))
2626
{
2727
GraphSession.Instance.GraphOption.EnableWAMForMSGraph = EnableLoginByWAM;
28-
WriteDebug($"Signin by Web Account Manager (WAM) is {(EnableLoginByWAM ? "enabled" : "disabled")}.");
28+
WriteDebug($"Requested to {(EnableLoginByWAM ? "enable" : "disable")} sign in by Web Account Manager (WAM).");
29+
WriteDebug("Note: Sign in by Web Account Manager (WAM) is mandatory for Microsoft Graph PowerShell SDK on Windows and cannot be disabled. This option is deprecated and no longer has any effect.");
2930
}
3031
File.WriteAllText(Constants.GraphOptionsFilePath, JsonConvert.SerializeObject(GraphSession.Instance.GraphOption, Formatting.Indented));
3132
}

0 commit comments

Comments
 (0)