From a198028cdd899a8125647f6e76ba9a1d1e53218c Mon Sep 17 00:00:00 2001 From: Peter Bajurny Date: Thu, 2 Jan 2020 13:01:00 -0600 Subject: [PATCH 1/6] More P12 options Allow the option to specify your own P12 password if you've re-exported the P12 with your own password. Also add the ability to use an X509Certificate2 object directly, useful for environments with some kind of secrets management that will handle this for you. --- .../Authentication/New-GoogleService.ps1 | 22 ++++++++++++++----- .../Configuration/Get-PSGSuiteConfig.ps1 | 2 ++ .../Configuration/Set-PSGSuiteConfig.ps1 | 13 ++++++++++- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/PSGSuite/Public/Authentication/New-GoogleService.ps1 b/PSGSuite/Public/Authentication/New-GoogleService.ps1 index 7352d8cf..0c490ceb 100644 --- a/PSGSuite/Public/Authentication/New-GoogleService.ps1 +++ b/PSGSuite/Public/Authentication/New-GoogleService.ps1 @@ -55,19 +55,31 @@ function New-GoogleService { $script:_PSGSuiteSessions[$sessionKey] | Select-Object -ExpandProperty Service } else { - if ($script:PSGSuite.P12KeyPath -or $script:PSGSuite.P12Key) { + if ($script:PSGSuite.P12KeyPath -or $script:PSGSuite.P12Key -or $script:PSGSuite.P12KeyObject) { try { Write-Verbose "Building ServiceAccountCredential from P12Key as user '$User'" - if (-not $script:PSGSuite.P12Key) { - $script:PSGSuite.P12Key = ([System.IO.File]::ReadAllBytes($script:PSGSuite.P12KeyPath)) - Set-PSGSuiteConfig -ConfigName $script:PSGSuite.ConfigName -P12Key $script:PSGSuite.P12Key -Verbose:$false + if ($script:PSGSuite.P12KeyPath -or $script:PSGSuite.P12Key) { + if (-not $script:PSGSuite.P12Key) { + $script:PSGSuite.P12Key = ([System.IO.File]::ReadAllBytes($script:PSGSuite.P12KeyPath)) + Set-PSGSuiteConfig -ConfigName $script:PSGSuite.ConfigName -P12Key $script:PSGSuite.P12Key -Verbose:$false + } + if ($script:PSGSuite.P12KeyPassword) { + $P12KeyPassword = $script:PSGSuite.P12KeyPassword + } + else { + $P12KeyPassword = "notasecret" + } + $certificate = New-Object 'System.Security.Cryptography.X509Certificates.X509Certificate2' -ArgumentList ([System.Byte[]]$script:PSGSuite.P12Key),$P12KeyPassword,([System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable) + } + else { + $certificate = $script:PSGSuite.P12KeyObject } - $certificate = New-Object 'System.Security.Cryptography.X509Certificates.X509Certificate2' -ArgumentList ([System.Byte[]]$script:PSGSuite.P12Key),"notasecret",([System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable) $credential = New-Object 'Google.Apis.Auth.OAuth2.ServiceAccountCredential' (New-Object 'Google.Apis.Auth.OAuth2.ServiceAccountCredential+Initializer' $script:PSGSuite.AppEmail -Property @{ User = $User Scopes = [string[]]$Scope } ).FromCertificate($certificate) + } catch { $PSCmdlet.ThrowTerminatingError($_) diff --git a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 index b6200290..7f9037c1 100644 --- a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 @@ -65,6 +65,8 @@ function Get-PSGSuiteConfig { @{l = 'ConfigName';e = {$choice}}, @{l = 'P12KeyPath';e = {Decrypt $_.P12KeyPath}}, 'P12Key', + @{l = 'P12KeyPassword';e = {Decrypt $_.P12KeyPassword}}, + 'P12KeyObject', @{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}}, @{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}}, @{l = 'AppEmail';e = {Decrypt $_.AppEmail}}, diff --git a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 index 65396cfa..b355df66 100644 --- a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 @@ -15,6 +15,9 @@ function Set-PSGSuiteConfig { .PARAMETER P12Key The P12Key in byte array format. If the actual P12Key is present on the config, the P12KeyPath is not needed. The config will auto-update with this value after running any command, if P12KeyPath is filled and this value is not already present. + .PARAMETER P12KeyPassword + The password for the P12 Key file. If not specified the default of 'notasecret' will be used and this config value will not be set. This is only needed in the case where the P12 file has been manually rexported with a custom password + .PARAMETER ClientSecretsPath The path to the Client Secrets JSON file downloaded from the Google Developer's Console. Using the ClientSecrets JSON will prompt the user to complete OAuth2 authentication in their browser on the first run and store the retrieved Refresh and Access tokens in the user's home directory. The config will auto-update with this value after running any command, if ClientSecretsPath is filled and this value is not already present. If P12KeyPath is also specified, ClientSecretsPath will be ignored. @@ -95,6 +98,9 @@ function Set-PSGSuiteConfig { [Byte[]] $P12Key, [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] + [SecureString] + $P12KeyPassword, + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [string] $ClientSecretsPath, [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] @@ -164,7 +170,7 @@ function Set-PSGSuiteConfig { } } Write-Verbose "Setting config name '$ConfigName'" - $configParams = @('P12Key','P12KeyPath','ClientSecretsPath','ClientSecrets','AppEmail','AdminEmail','CustomerID','Domain','Preference','ServiceAccountClientID','Webhook','Space') + $configParams = @('P12Key','P12KeyPath','P12KeyPassword','ClientSecretsPath','ClientSecrets','AppEmail','AdminEmail','CustomerID','Domain','Preference','ServiceAccountClientID','Webhook','Space') if ($SetAsDefaultConfig -or !$configHash["DefaultConfig"]) { $configHash["DefaultConfig"] = $ConfigName } @@ -190,6 +196,11 @@ function Set-PSGSuiteConfig { $configHash["$ConfigName"]['P12Key'] = ([System.IO.File]::ReadAllBytes($PSBoundParameters[$key])) } } + P12KeyPassword { + if (-not [System.String]""::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) { + $configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key]) + } + } ClientSecretsPath { if (-not [System.String]::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) { $configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key]) From b5d33088f21412ab850f1f40426ca5ad6d6c805f Mon Sep 17 00:00:00 2001 From: Peter Bajurny Date: Thu, 2 Jan 2020 18:40:19 -0600 Subject: [PATCH 2/6] Allow scriptblocks in configuration "Decrypt" a scriptblock by executing it --- PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 index 7f9037c1..982b25e3 100644 --- a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 @@ -57,6 +57,9 @@ function Get-PSGSuiteConfig { [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR( $String)) } + elseif ($String -is [ScriptBlock]) { + $String.InvokeReturnAsIs() + } else { $String } From af18771199700fe044ec4efa9c6ae01cb3f241c5 Mon Sep 17 00:00:00 2001 From: Peter Bajurny Date: Thu, 2 Jan 2020 19:49:16 -0600 Subject: [PATCH 3/6] Update Get-PSGSuiteConfig.ps1 need to decrypt the object as well --- PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 index 982b25e3..3c831923 100644 --- a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 @@ -69,7 +69,7 @@ function Get-PSGSuiteConfig { @{l = 'P12KeyPath';e = {Decrypt $_.P12KeyPath}}, 'P12Key', @{l = 'P12KeyPassword';e = {Decrypt $_.P12KeyPassword}}, - 'P12KeyObject', + @{l = 'P12KeyObject';e = {Decrypt $_.P12KeyObject}}, @{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}}, @{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}}, @{l = 'AppEmail';e = {Decrypt $_.AppEmail}}, From 6cbe2a010a2cd91626201fc3b788744760db36a8 Mon Sep 17 00:00:00 2001 From: Peter Bajurny Date: Sun, 5 Jan 2020 01:21:55 -0600 Subject: [PATCH 4/6] json service account modify config to hold service account key in json format --- .../Configuration/Get-PSGSuiteConfig.ps1 | 20 ++++++++++++++-- .../Configuration/Set-PSGSuiteConfig.ps1 | 23 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 index 3c831923..1fa968a6 100644 --- a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 @@ -70,14 +70,30 @@ function Get-PSGSuiteConfig { 'P12Key', @{l = 'P12KeyPassword';e = {Decrypt $_.P12KeyPassword}}, @{l = 'P12KeyObject';e = {Decrypt $_.P12KeyObject}}, + @{l = 'JSONServiceAccountKeyPath';e = {Decrypt $_.JSONServiceAccountKeyPath}}, + @{l = 'JSONServiceAccountKey';e = {Decrypt $_.JSONServiceAccountKey}}, @{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}}, @{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}}, - @{l = 'AppEmail';e = {Decrypt $_.AppEmail}}, + @{l = 'AppEmail';e = { + if ($_.JSONServiceAccountKey) { + ($_.JSONServiceAccountKey | ConvertFrom-Json).client_email + } + else { + Decrypt $_.AppEmail + } + }}, @{l = 'AdminEmail';e = {Decrypt $_.AdminEmail}}, @{l = 'CustomerID';e = {Decrypt $_.CustomerID}}, @{l = 'Domain';e = {Decrypt $_.Domain}}, @{l = 'Preference';e = {Decrypt $_.Preference}}, - @{l = 'ServiceAccountClientID';e = {Decrypt $_.ServiceAccountClientID}}, + @{l = 'ServiceAccountClientID';e = { + if ($_.JSONServiceAccountKey) { + ($_.JSONServiceAccountKey | ConvertFrom-Json).client_id + } + else { + Decrypt $_.ServiceAccountClientID + } + }}, @{l = 'Chat';e = { $dict = @{ Webhooks = @{} diff --git a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 index b355df66..a8ce86cd 100644 --- a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 @@ -18,6 +18,12 @@ function Set-PSGSuiteConfig { .PARAMETER P12KeyPassword The password for the P12 Key file. If not specified the default of 'notasecret' will be used and this config value will not be set. This is only needed in the case where the P12 file has been manually rexported with a custom password + .PARAMETER JSONServiceAccountKeyPath + The path to the Service Account JSON file downloaded from the Google Developer's Console. + + .PARAMETER JSONServiceAccountKey + The string contents of the Serivce Account JSON file downloaded from the Google Developer's Console. + .PARAMETER ClientSecretsPath The path to the Client Secrets JSON file downloaded from the Google Developer's Console. Using the ClientSecrets JSON will prompt the user to complete OAuth2 authentication in their browser on the first run and store the retrieved Refresh and Access tokens in the user's home directory. The config will auto-update with this value after running any command, if ClientSecretsPath is filled and this value is not already present. If P12KeyPath is also specified, ClientSecretsPath will be ignored. @@ -102,6 +108,12 @@ function Set-PSGSuiteConfig { $P12KeyPassword, [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [string] + $JSONServiceAccountKeyPath, + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] + [string] + $JSONServiceAccountKey, + [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] + [string] $ClientSecretsPath, [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [string] @@ -151,6 +163,9 @@ function Set-PSGSuiteConfig { elseif ($string -is [System.String] -and $String -notlike '') { ConvertTo-SecureString -String $string -AsPlainText -Force } + elseif ($string -is [System.Management.Automation.ScriptBlock]) { + $string + } } } Process { @@ -170,7 +185,7 @@ function Set-PSGSuiteConfig { } } Write-Verbose "Setting config name '$ConfigName'" - $configParams = @('P12Key','P12KeyPath','P12KeyPassword','ClientSecretsPath','ClientSecrets','AppEmail','AdminEmail','CustomerID','Domain','Preference','ServiceAccountClientID','Webhook','Space') + $configParams = @('P12Key','P12KeyPath','P12KeyPassword','JSONServiceAccountKeyPath','JSONServiceAccountKey','ClientSecretsPath','ClientSecrets','AppEmail','AdminEmail','CustomerID','Domain','Preference','ServiceAccountClientID','Webhook','Space') if ($SetAsDefaultConfig -or !$configHash["DefaultConfig"]) { $configHash["DefaultConfig"] = $ConfigName } @@ -201,6 +216,12 @@ function Set-PSGSuiteConfig { $configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key]) } } + JSONServiceAccountKeyPath { + if (-not [System.String]::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) { + $configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key]) + $configHash["$ConfigName"]['JSONServiceAccountKey'] = (Encrypt $(Get-Content $PSBoundParameters[$key] -Raw)) + } + } ClientSecretsPath { if (-not [System.String]::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) { $configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key]) From 466398a6741eae942f259a91917163facc461482 Mon Sep 17 00:00:00 2001 From: Peter Bajurny Date: Sun, 5 Jan 2020 01:36:35 -0600 Subject: [PATCH 5/6] json service key support json service account key in new-google service need to document precedence of 3 key types in set-config --- .../Authentication/New-GoogleService.ps1 | 23 +++++++++++++++++-- .../Configuration/Set-PSGSuiteConfig.ps1 | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/PSGSuite/Public/Authentication/New-GoogleService.ps1 b/PSGSuite/Public/Authentication/New-GoogleService.ps1 index 0c490ceb..a7d19f7e 100644 --- a/PSGSuite/Public/Authentication/New-GoogleService.ps1 +++ b/PSGSuite/Public/Authentication/New-GoogleService.ps1 @@ -55,7 +55,26 @@ function New-GoogleService { $script:_PSGSuiteSessions[$sessionKey] | Select-Object -ExpandProperty Service } else { - if ($script:PSGSuite.P12KeyPath -or $script:PSGSuite.P12Key -or $script:PSGSuite.P12KeyObject) { + if ($script:PSGSuite.JSONServiceAccountKey -or $script:PSGSuite.JSONServiceAccountKeyPath) { + Write-Verbose "Building ServiceAccountCredential from JSONServiceAccountKey as user '$User'" + try { + if (-not $script:PSGSuite.JSONServiceAccountKey) { + $script:PSGSuite.JSONServiceAccountKey = ([System.IO.File]::ReadAllBytes($script:PSGSuite.JSONServiceAccountKeyPath)) + Set-PSGSuiteConfig -ConfigName $script:PSGSuite.ConfigName -JSONServiceAccountKey $script:PSGSuite.JSONServiceAccountKey -Verbose:$false + } + $stream = New-Object System.IO.MemoryStream $([System.Text.Encoding]::ASCII.GetBytes($script:PSGSuite.JSONServiceAccountKey)), $null + $credential = ([Google.Apis.Auth.OAuth2.GoogleCredential]::FromStream($stream)).CreateWithUser($User).CreateScoped($Scope).UnderlyingCredential + } + catch { + $PSCmdlet.ThrowTerminatingError($_) + } + finally { + if ($stream) { + $stream.Close() + } + } + } + elseif ($script:PSGSuite.P12KeyPath -or $script:PSGSuite.P12Key -or $script:PSGSuite.P12KeyObject) { try { Write-Verbose "Building ServiceAccountCredential from P12Key as user '$User'" if ($script:PSGSuite.P12KeyPath -or $script:PSGSuite.P12Key) { @@ -128,7 +147,7 @@ function New-GoogleService { } } else { - $PSCmdlet.ThrowTerminatingError((ThrowTerm "The current config '$($script:PSGSuite.ConfigName)' does not contain a P12KeyPath or a ClientSecretsPath! PSGSuite is unable to build a credential object for the service without a path to a credential file! Please update the configuration to include a path at least one of the two credential types.")) + $PSCmdlet.ThrowTerminatingError((ThrowTerm "The current config '$($script:PSGSuite.ConfigName)' does not contain a JSONServiceAccountKeyPath, P12KeyPath, or ClientSecretsPath! PSGSuite is unable to build a credential object for the service without a path to a credential file! Please update the configuration to include a path at least one of the three credential types.")) } $svc = New-Object "$ServiceType" (New-Object 'Google.Apis.Services.BaseClientService+Initializer' -Property @{ HttpClientInitializer = $credential diff --git a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 index a8ce86cd..afded30c 100644 --- a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 @@ -25,10 +25,10 @@ function Set-PSGSuiteConfig { The string contents of the Serivce Account JSON file downloaded from the Google Developer's Console. .PARAMETER ClientSecretsPath - The path to the Client Secrets JSON file downloaded from the Google Developer's Console. Using the ClientSecrets JSON will prompt the user to complete OAuth2 authentication in their browser on the first run and store the retrieved Refresh and Access tokens in the user's home directory. The config will auto-update with this value after running any command, if ClientSecretsPath is filled and this value is not already present. If P12KeyPath is also specified, ClientSecretsPath will be ignored. + The path to the Client Secrets JSON file downloaded from the Google Developer's Console. Using the ClientSecrets JSON will prompt the user to complete OAuth2 authentication in their browser on the first run and store the retrieved Refresh and Access tokens in the user's home directory. The config will auto-update with this value after running any command, if ClientSecretsPath is filled and this value is not already present. If JSONServiceAccountKeyPath or P12KeyPath is also specified, ClientSecretsPath will be ignored. .PARAMETER ClientSecrets - The string contents of the Client Secrets JSON file downloaded from the Google Developer's Console. Using the ClientSecrets JSON will prompt the user to complete OAuth2 authentication in their browser on the first run and store the retrieved Refresh and Access tokens in the user's home directory. If P12KeyPath is also specified, ClientSecrets will be ignored. + The string contents of the Client Secrets JSON file downloaded from the Google Developer's Console. Using the ClientSecrets JSON will prompt the user to complete OAuth2 authentication in their browser on the first run and store the retrieved Refresh and Access tokens in the user's home directory. If JSONServiceAccountKeyPath or P12KeyPath is also specified, ClientSecrets will be ignored. .PARAMETER AppEmail The application email from the Google Developer's Console. This typically looks like the following: From 63ee83f4f8377636f76a04c1762f90a041ced305 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Fri, 28 Feb 2020 00:39:40 -0600 Subject: [PATCH 6/6] removed JSONServiceAccountKey + JSONServiceAccountKeyPath parameters due to not being needed --- .../Configuration/Get-PSGSuiteConfig.ps1 | 18 +++++++------- .../Configuration/Set-PSGSuiteConfig.ps1 | 24 ++----------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 index 1fa968a6..d5030844 100644 --- a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 @@ -70,16 +70,14 @@ function Get-PSGSuiteConfig { 'P12Key', @{l = 'P12KeyPassword';e = {Decrypt $_.P12KeyPassword}}, @{l = 'P12KeyObject';e = {Decrypt $_.P12KeyObject}}, - @{l = 'JSONServiceAccountKeyPath';e = {Decrypt $_.JSONServiceAccountKeyPath}}, - @{l = 'JSONServiceAccountKey';e = {Decrypt $_.JSONServiceAccountKey}}, @{l = 'ClientSecretsPath';e = {Decrypt $_.ClientSecretsPath}}, @{l = 'ClientSecrets';e = {Decrypt $_.ClientSecrets}}, @{l = 'AppEmail';e = { - if ($_.JSONServiceAccountKey) { - ($_.JSONServiceAccountKey | ConvertFrom-Json).client_email + if ($_.AppEmail) { + Decrypt $_.ServiceAccountClientID } - else { - Decrypt $_.AppEmail + elseif ($_.ClientSecrets) { + (Decrypt $_.ClientSecrets | ConvertFrom-Json).client_email } }}, @{l = 'AdminEmail';e = {Decrypt $_.AdminEmail}}, @@ -87,12 +85,12 @@ function Get-PSGSuiteConfig { @{l = 'Domain';e = {Decrypt $_.Domain}}, @{l = 'Preference';e = {Decrypt $_.Preference}}, @{l = 'ServiceAccountClientID';e = { - if ($_.JSONServiceAccountKey) { - ($_.JSONServiceAccountKey | ConvertFrom-Json).client_id - } - else { + if ($_.ServiceAccountClientID) { Decrypt $_.ServiceAccountClientID } + elseif ($_.ClientSecrets) { + (Decrypt $_.ClientSecrets | ConvertFrom-Json).client_id + } }}, @{l = 'Chat';e = { $dict = @{ diff --git a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 index afded30c..279ed2aa 100644 --- a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 @@ -18,12 +18,6 @@ function Set-PSGSuiteConfig { .PARAMETER P12KeyPassword The password for the P12 Key file. If not specified the default of 'notasecret' will be used and this config value will not be set. This is only needed in the case where the P12 file has been manually rexported with a custom password - .PARAMETER JSONServiceAccountKeyPath - The path to the Service Account JSON file downloaded from the Google Developer's Console. - - .PARAMETER JSONServiceAccountKey - The string contents of the Serivce Account JSON file downloaded from the Google Developer's Console. - .PARAMETER ClientSecretsPath The path to the Client Secrets JSON file downloaded from the Google Developer's Console. Using the ClientSecrets JSON will prompt the user to complete OAuth2 authentication in their browser on the first run and store the retrieved Refresh and Access tokens in the user's home directory. The config will auto-update with this value after running any command, if ClientSecretsPath is filled and this value is not already present. If JSONServiceAccountKeyPath or P12KeyPath is also specified, ClientSecretsPath will be ignored. @@ -108,12 +102,6 @@ function Set-PSGSuiteConfig { $P12KeyPassword, [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [string] - $JSONServiceAccountKeyPath, - [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] - [string] - $JSONServiceAccountKey, - [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] - [string] $ClientSecretsPath, [parameter(Mandatory = $false,ValueFromPipelineByPropertyName = $true)] [string] @@ -185,7 +173,7 @@ function Set-PSGSuiteConfig { } } Write-Verbose "Setting config name '$ConfigName'" - $configParams = @('P12Key','P12KeyPath','P12KeyPassword','JSONServiceAccountKeyPath','JSONServiceAccountKey','ClientSecretsPath','ClientSecrets','AppEmail','AdminEmail','CustomerID','Domain','Preference','ServiceAccountClientID','Webhook','Space') + $configParams = @('P12Key','P12KeyPath','P12KeyPassword','ClientSecretsPath','ClientSecrets','AppEmail','AdminEmail','CustomerID','Domain','Preference','ServiceAccountClientID','Webhook','Space') if ($SetAsDefaultConfig -or !$configHash["DefaultConfig"]) { $configHash["DefaultConfig"] = $ConfigName } @@ -212,15 +200,7 @@ function Set-PSGSuiteConfig { } } P12KeyPassword { - if (-not [System.String]""::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) { - $configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key]) - } - } - JSONServiceAccountKeyPath { - if (-not [System.String]::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) { - $configHash["$ConfigName"][$key] = (Encrypt $PSBoundParameters[$key]) - $configHash["$ConfigName"]['JSONServiceAccountKey'] = (Encrypt $(Get-Content $PSBoundParameters[$key] -Raw)) - } + $configHash["$ConfigName"][$key] = $PSBoundParameters[$key] } ClientSecretsPath { if (-not [System.String]::IsNullOrWhiteSpace($PSBoundParameters[$key].Trim())) {