Skip to content

Commit 8b98142

Browse files
Making updates to WAM implementation (#2100)
Adding Documentation for WAM Integration and making modifications to existing WAM integration --------- Co-authored-by: Peter Ombwa <[email protected]>
1 parent d7309c3 commit 8b98142

File tree

7 files changed

+107
-4
lines changed

7 files changed

+107
-4
lines changed

docs/authentication.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ The Microsoft Graph PowerShell module supports two types of authentication:
55
- Delegated Access
66
- App-only Access
77

8+
## Web Account Manager (WAM)
9+
WAM is a Windows 10+ component that acts as an authentication broker allowing the users of an app benefit from integration with accounts known to Windows, such as the account already signed into an active Windows session.
10+
11+
Microsoft Graph PowerShell module supports WAM in the following scenraio:
12+
13+
- To enable WAM on supported devices
14+
```PowerShell
15+
Set-MgGraphOption -EnableLoginByWAM $true
16+
```
17+
18+
- To disable WAM on supported devices
19+
```PowerShell
20+
Set-MgGraphOption -EnableLoginByWAM $false
21+
```
822
## Delegated Access
923

1024
Delegated access uses a public client to get an access token and consume Microsoft Graph resources on behalf of the signed-in user.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// ------------------------------------------------------------------------------
2+
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
// ------------------------------------------------------------------------------
4+
5+
using Newtonsoft.Json.Linq;
6+
using System.IO;
7+
using System.Management.Automation;
8+
9+
namespace Microsoft.Graph.PowerShell.Authentication.Cmdlets
10+
{
11+
[Cmdlet(VerbsCommon.Get, "MgGraphOption", HelpUri = "")]
12+
[OutputType(typeof(IGraphOption))]
13+
public class GetMgGraphOption : PSCmdlet
14+
{
15+
protected override void BeginProcessing()
16+
{
17+
base.BeginProcessing();
18+
}
19+
20+
protected override void ProcessRecord()
21+
{
22+
base.ProcessRecord();
23+
WriteObject(GraphSession.Instance.GraphOption);
24+
}
25+
26+
protected override void EndProcessing()
27+
{
28+
base.EndProcessing();
29+
}
30+
31+
protected override void StopProcessing()
32+
{
33+
base.StopProcessing();
34+
}
35+
}
36+
}

src/Authentication/Authentication/Cmdlets/SetMgGraphOption.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ protected override void ProcessRecord()
2525
if (this.IsParameterBound(nameof(EnableLoginByWAM)))
2626
{
2727
GraphSession.Instance.GraphOption.EnableWAMForMSGraph = EnableLoginByWAM;
28-
var message = $"Signin by Web Account Manager (WAM) is {(EnableLoginByWAM ? "enabled" : "disabled")}.";
29-
WriteObject(message);
28+
WriteDebug($"Signin by Web Account Manager (WAM) is {(EnableLoginByWAM ? "enabled" : "disabled")}.");
3029
}
3130
File.WriteAllText(Constants.GraphOptionsFilePath, JsonConvert.SerializeObject(GraphSession.Instance.GraphOption, Formatting.Indented));
3231
}

src/Authentication/Authentication/Microsoft.Graph.Authentication.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ FunctionsToExport = 'Find-MgGraphCommand', 'Find-MgGraphPermission'
7575
CmdletsToExport = 'Connect-MgGraph', 'Disconnect-MgGraph', 'Get-MgContext',
7676
'Invoke-MgGraphRequest', 'Add-MgEnvironment', 'Get-MgEnvironment',
7777
'Remove-MgEnvironment', 'Set-MgEnvironment', 'Get-MgRequestContext',
78-
'Set-MgRequestContext', 'Set-MgGraphOption'
78+
'Set-MgRequestContext', 'Set-MgGraphOption', 'Get-MgGraphOption'
7979

8080
# Variables to export from this module
8181
VariablesToExport = '*'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
# ------------------------------------------------------------------------------
4+
5+
Describe "Get-MgGraphOption Command" {
6+
BeforeAll {
7+
$ModuleName = "Microsoft.Graph.Authentication"
8+
$ModulePath = Join-Path $PSScriptRoot "..\artifacts\$ModuleName.psd1"
9+
Import-Module $ModulePath -Force
10+
}
11+
Context "When executing the command" {
12+
it 'Should have one ParameterSets' {
13+
$GetMgGraphOptionCommand = Get-Command Set-MgGraphOption
14+
$GetMgGraphOptionCommand | Should -Not -BeNullOrEmpty
15+
$GetMgGraphOptionCommand.ParameterSets | Should -HaveCount 1
16+
$GetMgGraphOptionCommand.ParameterSets.Parameters | Should -HaveCount 12 # PS common parameters.
17+
}
18+
19+
It 'Executes successfully' {
20+
{ Get-MgGraphOption -Debug | Out-Null } | Should -Not -Be $null
21+
{ Get-MgGraphOption -ErrorAction SilentlyContinue } | Should -Not -Throw
22+
}
23+
}
24+
}

src/Authentication/Authentication/test/Microsoft.Graph.Authentication.Tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Describe "Microsoft.Graph.Authentication module" {
5151
"Invoke-MgRestMethod",
5252
"Get-MgRequestContext",
5353
"Set-MgRequestContext",
54-
"Set-MgGraphOption"
54+
"Set-MgGraphOption",
55+
"Get-MgGraphOption"
5556
)
5657

5758
$PSModuleInfo.ExportedCommands.Keys | Should -BeIn $ExpectedCommands
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# ------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
3+
# ------------------------------------------------------------------------------
4+
5+
Describe "Set-MgGraphOption" {
6+
BeforeAll {
7+
$ModuleName = "Microsoft.Graph.Authentication"
8+
$ModulePath = Join-Path $PSScriptRoot "..\artifacts\$ModuleName.psd1"
9+
Import-Module $ModulePath -Force -ErrorAction SilentlyContinue
10+
}
11+
Context "When executing the command" {
12+
it 'Should have one ParameterSets' {
13+
$SetMgGraphOptionCommand = Get-Command Set-MgGraphOption
14+
$SetMgGraphOptionCommand | Should -Not -BeNullOrEmpty
15+
$SetMgGraphOptionCommand.ParameterSets | Should -HaveCount 1
16+
$SetMgGraphOptionCommand.ParameterSets.Parameters | Should -HaveCount 12 # PS common parameters.
17+
}
18+
19+
It 'Executes successfully whren toggling WAM on' {
20+
{ Set-MgGraphOption -EnableLoginByWAM $true -Debug | Out-Null } | Should -Not -Be $null
21+
{ Set-MgGraphOption -EnableLoginByWAM $true -ErrorAction SilentlyContinue } | Should -Not -Throw
22+
}
23+
24+
It 'Executes successfully when toggling WAM off' {
25+
{ Set-MgGraphOption -EnableLoginByWAM $false -Debug | Out-Null } | Should -Not -Be $null
26+
{ Set-MgGraphOption -EnableLoginByWAM $false -ErrorAction SilentlyContinue } | Should -Not -Throw
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)