- Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathutils.ps1
27 lines (25 loc) · 1.29 KB
/
utils.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. See License in the project root for license information.
<#
Connect to the Graph Tenant
#>
FunctionConnect-GraphTenant {
$defaultCertificate=Get-LocalCertificate
#Connect To Microsoft Graph Raptor Default Tenant Using ClientId, TenantId and Certificate
if ($null-eq$defaultCertificate) {
Connect-MgGraph-CertificateThumbprint ${env:CERTIFICATETHUMBPRINT}-ClientId ${env:CLIENTIDENTIFIER}-TenantId ${env:TENANTIDENTIFIER}|Out-Null
}
else {
Connect-MgGraph-Certificate $defaultCertificate-ClientId ${env:CLIENTIDENTIFIER}-TenantId ${env:TENANTIDENTIFIER}|Out-Null
}
}
<#
Get Certificate from Azure KeyVault loaded via Environment variable
#>
FunctionGet-LocalCertificate {
if (($null-eq$global:DefaultCertificate) -and ($null-ne$env:CLIENTCERTIFICATE)) {
$kvSecretBytes= [System.Convert]::FromBase64String($env:CLIENTCERTIFICATE)
$pfxCertificate=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @($kvSecretBytes,"", [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$global:DefaultCertificate=$pfxCertificate
}
return$global:DefaultCertificate
}