Skip to content

Commit cd7292f

Browse files
authored
Merge pull request #8 from CriticalSolutionsNetwork/Update-authentication-to-api
Update authentication to api
2 parents 9241185 + b4069a0 commit cd7292f

32 files changed

+1294
-574
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ node_modules
1717
package-lock.json
1818
ZZBuild-Help.ps1
1919
test1.ps1
20-
helpdoc.ps1
20+
helpdoc.ps1
21+
StyleGuide.md

CHANGELOG.md

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
### Added
99

10+
- Added Get-TkMsalToken cmdlet to retrieve an MSAL token using API calls.
11+
- Added Managed Identity support for Get-TkMsalToken cmdlet (Needs to be tested).
12+
- SecureString support for Get-TkMsalToken cmdlet.
13+
- Formatting alignment for cmdlets.
14+
15+
### Fixed
16+
17+
- Fixed authentication context for MgGraph.
18+
19+
### Changed
20+
21+
- Updated private function names to be more descriptive.
22+
- Removed MSAL.PS dependency from Send-TkEmailAppMessage function.
23+
- Removed Send-TkEmailAppMessage module install if manual parameters are provided.
24+
25+
## [0.2.0] - 2025-03-14
26+
27+
### Added
28+
1029
- Updated docs for the module.
1130
- Release Candidate
1231
- Update wiki pages.

README.md

+26-23
Large diffs are not rendered by default.

README2.md

+25-21
Large diffs are not rendered by default.

docs/index.html

+39-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<!--
33
<auto-generated>
44
<synopsis>
5-
This code was generated by a psDoc. on: 03/14/2025 14:18:51
5+
This code was generated by a psDoc. on: 03/17/2025 08:59:20
66
Get it here: https://github.com/ChaseFlorell/psDoc
77
</synopsis>
88
<description>
@@ -130,9 +130,9 @@ <h3> Syntax </h3>
130130
</div>
131131
<div class="panel panel-default">
132132
<div class='panel-body'>
133-
<pre class="brush: ps">New-MailEnabledSendingGroup -Name &lt;String&gt; [-Alias &lt;String&gt;] -PrimarySmtpAddress &lt;String&gt; [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]
133+
<pre class="brush: ps">New-MailEnabledSendingGroup -Name &lt;String&gt; [-Alias &lt;String&gt;] -PrimarySmtpAddress &lt;String&gt; [-LogOutputPath &lt;String&gt;] [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]
134134

135-
New-MailEnabledSendingGroup -Name &lt;String&gt; [-Alias &lt;String&gt;] -DefaultDomain &lt;String&gt; [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]</pre>
135+
New-MailEnabledSendingGroup -Name &lt;String&gt; [-Alias &lt;String&gt;] -DefaultDomain &lt;String&gt; [-LogOutputPath &lt;String&gt;] [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]</pre>
136136
</div>
137137
</div>
138138
<div>
@@ -188,6 +188,15 @@ <h3> Parameters </h3>
188188
<td class="visible-lg">false</td>
189189
<td class="visible-lg"></td>
190190
</tr>
191+
<tr>
192+
<td><nobr>-LogOutputPath</nobr></td>
193+
<td class="visible-lg visible-md"></td>
194+
<td><p>An optional path to output the log file. If not provided, logs will not be written to a file.</p>
195+
</td>
196+
<td class="visible-lg visible-md">false</td>
197+
<td class="visible-lg">false</td>
198+
<td class="visible-lg"></td>
199+
</tr>
191200
<tr>
192201
<td><nobr>-WhatIf</nobr></td>
193202
<td class="visible-lg visible-md">wi</td>
@@ -262,9 +271,9 @@ <h3> Syntax </h3>
262271
</div>
263272
<div class="panel panel-default">
264273
<div class='panel-body'>
265-
<pre class="brush: ps">Publish-TkEmailApp [-AppPrefix &lt;String&gt;] -AuthorizedSenderUserName &lt;String&gt; -MailEnabledSendingGroup &lt;String&gt; [-CertPrefix &lt;String&gt;] [-CertThumbprint &lt;String&gt;] [-KeyExportPolicy &lt;String&gt;] [-VaultName &lt;String&gt;] [-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [&lt;CommonParameters&gt;]
274+
<pre class="brush: ps">Publish-TkEmailApp [-AppPrefix &lt;String&gt;] -AuthorizedSenderUserName &lt;String&gt; -MailEnabledSendingGroup &lt;String&gt; [-CertPrefix &lt;String&gt;] [-CertThumbprint &lt;String&gt;] [-KeyExportPolicy &lt;String&gt;] [-VaultName &lt;String&gt;] [-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [-LogOutput &lt;String&gt;] [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]
266275

267-
Publish-TkEmailApp -ExistingAppObjectId &lt;String&gt; -CertPrefix &lt;String&gt; [-CertThumbprint &lt;String&gt;] [-KeyExportPolicy &lt;String&gt;] [-VaultName &lt;String&gt;] [-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [&lt;CommonParameters&gt;]</pre>
276+
Publish-TkEmailApp -ExistingAppObjectId &lt;String&gt; -CertPrefix &lt;String&gt; [-CertThumbprint &lt;String&gt;] [-KeyExportPolicy &lt;String&gt;] [-VaultName &lt;String&gt;] [-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [-LogOutput &lt;String&gt;] [-WhatIf] [-Confirm] [&lt;CommonParameters&gt;]</pre>
268277
</div>
269278
</div>
270279
<div>
@@ -380,6 +389,31 @@ <h3> Parameters </h3>
380389
<td class="visible-lg">false</td>
381390
<td class="visible-lg">False</td>
382391
</tr>
392+
<tr>
393+
<td><nobr>-LogOutput</nobr></td>
394+
<td class="visible-lg visible-md"></td>
395+
<td><p>If specified, log the output to the console.</p>
396+
</td>
397+
<td class="visible-lg visible-md">false</td>
398+
<td class="visible-lg">false</td>
399+
<td class="visible-lg"></td>
400+
</tr>
401+
<tr>
402+
<td><nobr>-WhatIf</nobr></td>
403+
<td class="visible-lg visible-md">wi</td>
404+
<td></td>
405+
<td class="visible-lg visible-md">false</td>
406+
<td class="visible-lg">false</td>
407+
<td class="visible-lg"></td>
408+
</tr>
409+
<tr>
410+
<td><nobr>-Confirm</nobr></td>
411+
<td class="visible-lg visible-md">cf</td>
412+
<td></td>
413+
<td class="visible-lg visible-md">false</td>
414+
<td class="visible-lg">false</td>
415+
<td class="visible-lg"></td>
416+
</tr>
383417
</tbody>
384418
</table>
385419
</div>

help/GraphAppToolkit.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
Module Name: GraphAppToolkit
33
Module Guid: b5426317-5612-4483-b664-beafc448bc2f
44
Download Help Link: {{ Update Download Link }}

help/New-MailEnabledSendingGroup.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ Creates or retrieves a mail-enabled security group with a custom or default doma
1515
### CustomDomain (Default)
1616
```
1717
New-MailEnabledSendingGroup -Name <String> [-Alias <String>] -PrimarySmtpAddress <String>
18-
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
18+
[-LogOutputPath <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
1919
```
2020

2121
### DefaultDomain
2222
```
23-
New-MailEnabledSendingGroup -Name <String> [-Alias <String>] -DefaultDomain <String>
23+
New-MailEnabledSendingGroup -Name <String> [-Alias <String>] -DefaultDomain <String> [-LogOutputPath <String>]
2424
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
2525
```
2626

@@ -123,6 +123,22 @@ Accept pipeline input: False
123123
Accept wildcard characters: False
124124
```
125125
126+
### -LogOutputPath
127+
An optional path to output the log file.
128+
If not provided, logs will not be written to a file.
129+
130+
```yaml
131+
Type: String
132+
Parameter Sets: (All)
133+
Aliases:
134+
135+
Required: False
136+
Position: Named
137+
Default value: None
138+
Accept pipeline input: False
139+
Accept wildcard characters: False
140+
```
141+
126142
### -WhatIf
127143
Shows what would happen if the cmdlet runs.
128144
The cmdlet is not run.

help/Publish-TkEmailApp.md

+49-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ Publishes a new or existing Graph Email App with specified configurations.
1616
```
1717
Publish-TkEmailApp [-AppPrefix <String>] -AuthorizedSenderUserName <String> -MailEnabledSendingGroup <String>
1818
[-CertPrefix <String>] [-CertThumbprint <String>] [-KeyExportPolicy <String>] [-VaultName <String>]
19-
[-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [-ProgressAction <ActionPreference>]
20-
[<CommonParameters>]
19+
[-OverwriteVaultSecret] [-ReturnParamSplat] [-DoNotUseDomainSuffix] [-LogOutput <String>]
20+
[-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm] [<CommonParameters>]
2121
```
2222

2323
### UseExistingApp
2424
```
2525
Publish-TkEmailApp -ExistingAppObjectId <String> -CertPrefix <String> [-CertThumbprint <String>]
2626
[-KeyExportPolicy <String>] [-VaultName <String>] [-OverwriteVaultSecret] [-ReturnParamSplat]
27-
[-DoNotUseDomainSuffix] [-ProgressAction <ActionPreference>] [<CommonParameters>]
27+
[-DoNotUseDomainSuffix] [-LogOutput <String>] [-ProgressAction <ActionPreference>] [-WhatIf] [-Confirm]
28+
[<CommonParameters>]
2829
```
2930

3031
## DESCRIPTION
@@ -315,6 +316,51 @@ Accept pipeline input: False
315316
Accept wildcard characters: False
316317
```
317318
319+
### -LogOutput
320+
If specified, log the output to the console.
321+
322+
```yaml
323+
Type: String
324+
Parameter Sets: (All)
325+
Aliases:
326+
327+
Required: False
328+
Position: Named
329+
Default value: None
330+
Accept pipeline input: False
331+
Accept wildcard characters: False
332+
```
333+
334+
### -WhatIf
335+
Shows what would happen if the cmdlet runs. The cmdlet is not run.
336+
337+
```yaml
338+
Type: SwitchParameter
339+
Parameter Sets: (All)
340+
Aliases: wi
341+
342+
Required: False
343+
Position: Named
344+
Default value: None
345+
Accept pipeline input: False
346+
Accept wildcard characters: False
347+
```
348+
349+
### -Confirm
350+
Prompts you for confirmation before running the cmdlet.
351+
352+
```yaml
353+
Type: SwitchParameter
354+
Parameter Sets: (All)
355+
Aliases: cf
356+
357+
Required: False
358+
Position: Named
359+
Default value: None
360+
Accept pipeline input: False
361+
Accept wildcard characters: False
362+
```
363+
318364
### -ProgressAction
319365
{{ Fill ProgressAction Description }}
320366

source/Private/Connect-TkMsService.ps1

+7-15
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,17 @@ function Connect-TkMsService {
3030
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
3131
param (
3232
[Parameter(
33-
HelpMessage = 'Connect to Microsoft Graph.'
33+
HelpMessage = 'Switch to connect to Microsoft Graph.'
3434
)]
3535
[Switch]
3636
$MgGraph,
3737
[Parameter(
38-
HelpMessage = 'Graph Scopes.'
38+
HelpMessage = 'Array of scopes required for Microsoft Graph authentication.'
3939
)]
4040
[String[]]
4141
$GraphAuthScopes,
4242
[Parameter(
43-
HelpMessage = 'Connect to Exchange Online.'
43+
HelpMessage = 'Switch to connect to Exchange Online.'
4444
)]
4545
[Switch]
4646
$ExchangeOnline
@@ -68,14 +68,6 @@ function Connect-TkMsService {
6868
Get-MgUser -Top 1 -ErrorAction Stop | Out-Null
6969
$ContextMg = Get-MgContext -ErrorAction Stop
7070
# Check required scopes
71-
<#
72-
$scopesNeeded = @(
73-
'Application.ReadWrite.All',
74-
'DelegatedPermissionGrant.ReadWrite.All',
75-
'Directory.ReadWrite.All',
76-
'RoleManagement.ReadWrite.Directory'
77-
)
78-
#>
7971
$scopesNeeded = $GraphAuthScopes
8072
$missing = $scopesNeeded | Where-Object { $ContextMg.Scopes -notcontains $_ }
8173
if ($missing) {
@@ -102,16 +94,16 @@ function Connect-TkMsService {
10294
# Remove the old context so we can connect fresh
10395
Remove-MgContext -ErrorAction SilentlyContinue
10496
Write-AuditLog 'Creating a new Microsoft Graph session.'
105-
Connect-MgGraph -Scopes $scopesNeeded `
106-
-ErrorAction Stop
97+
Connect-MgGraph -ContextScope Process -Scopes $scopesNeeded `
98+
-ErrorAction Stop | Out-Null
10799
Write-AuditLog 'Connected to Microsoft Graph.'
108100
}
109101
}
110102
else {
111103
# No valid session, so just connect
112104
Write-AuditLog 'No valid Microsoft Graph session found. Connecting...'
113-
Connect-MgGraph -Scopes $scopesNeeded `
114-
-ErrorAction Stop
105+
Connect-MgGraph -ContextScope Process -Scopes $scopesNeeded `
106+
-ErrorAction Stop | Out-Null
115107
Write-AuditLog 'Connected to Microsoft Graph.'
116108
}
117109
}

source/Private/ConvertTo-ParameterSplat.ps1

+7-2
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
}
1818
.NOTES
1919
Author: DrIOSx
20-
Date: YYYY-MM-DD
20+
Last Updated: 2025-03-16
2121
#>
2222
function ConvertTo-ParameterSplat {
2323
[CmdletBinding()]
2424
[OutputType([string])]
2525
param (
26-
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
26+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, HelpMessage = 'The object whose properties will be converted into a parameter splatting hashtable script.')]
27+
[ValidateNotNullOrEmpty()]
2728
[PSObject]$InputObject
2829
)
2930
process {
31+
Write-AuditLog -Message "Starting ConvertTo-ParameterSplat function." -Severity "Information"
32+
3033
$splatScript = "`$params = @{`n"
3134
$InputObject.psobject.Properties | ForEach-Object {
3235
$value = $_.Value
@@ -36,6 +39,8 @@ function ConvertTo-ParameterSplat {
3639
$splatScript += " $($_.Name) = $value`n"
3740
}
3841
$splatScript += "}"
42+
43+
Write-AuditLog -Message "Completed ConvertTo-ParameterSplat function." -Severity "Information"
3944
Write-Output $splatScript
4045
}
4146
}

source/Private/Get-TkExistingCert.ps1

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@
1818
function Get-TkExistingCert {
1919
[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
2020
param (
21-
[Parameter(Mandatory = $true)]
21+
[Parameter(Mandatory = $true, HelpMessage = 'The subject name of the certificate to search for in the current user''s certificate store.')]
2222
[string]$CertName
2323
)
24+
25+
if (-not $script:LogString) {
26+
Write-AuditLog -Start
27+
}
28+
else {
29+
Write-AuditLog -BeginFunction
30+
}
31+
2432
$ExistingCert = Get-ChildItem -Path Cert:\CurrentUser\My -ErrorAction SilentlyContinue |
2533
Where-Object { $_.Subject -eq $CertName } -ErrorAction SilentlyContinue
34+
2635
if ( $ExistingCert) {
2736
$VerbosePreference = 'Continue'
2837
Write-AuditLog "Certificate with subject '$CertName' already exists in the certificate store."
@@ -31,7 +40,7 @@ function Get-TkExistingCert {
3140
Write-AuditLog "Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { `$_.Subject -eq '$CertName' }"
3241
Write-AuditLog '2. If you are comfortable removing the old certificate, and any duplicates, run the following command:'
3342
Write-AuditLog "Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { `$_.Subject -eq '$CertName' } | Remove-Item"
34-
Write-AuditLog "If you would like to remove the certificate, confirm the operation when prompted."
43+
Write-AuditLog 'If you would like to remove the certificate, confirm the operation when prompted.'
3544
$shouldProcessOperation = 'Remove-Item'
3645
$shouldProcessTarget = "Certificate with subject '$CertName' with thumbprint $($ExistingCert.Thumbprint)"
3746
if ($PSCmdlet.ShouldProcess($shouldProcessTarget, $shouldProcessOperation)) {
@@ -47,4 +56,6 @@ function Get-TkExistingCert {
4756
else {
4857
Write-AuditLog "Certificate with subject '$CertName' does not exist in the certificate store. Continuing..."
4958
}
59+
60+
Write-AuditLog -EndFunction
5061
}

source/Private/Get-TkExistingSecret.ps1

+11-5
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,18 @@ function Get-TkExistingSecret {
2626
[string]$AppName,
2727
[string]$VaultName = 'GraphEmailAppLocalStore'
2828
)
29-
$ExistingSecret = Get-Secret -Name "$AppName" -Vault $VaultName -ErrorAction SilentlyContinue
30-
if ($ExistingSecret) {
31-
return $true
29+
Write-AuditLog -BeginFunction
30+
try {
31+
$ExistingSecret = Get-Secret -Name "$AppName" -Vault $VaultName -ErrorAction SilentlyContinue
32+
if ($ExistingSecret) {
33+
return $true
34+
}
35+
else {
36+
return $false
37+
}
3238
}
33-
else {
34-
return $false
39+
finally {
40+
Write-AuditLog -EndFunction
3541
}
3642
}
3743

0 commit comments

Comments
 (0)