Skip to content

Commit

Permalink
!deploy v2.21.3 - fix for client_secrets.json auth on PowerShell Core…
Browse files Browse the repository at this point in the history
… to Prompt instead, added OutputType to all relevant functions

## 2.21.3

* [Issue #131](#131)
  * Fixed: Changed `CodeReceiver` to use `PromptCodeReceiver` when client is PowerShell Core, as `LocalServerCodeReceiver` does not appear to redirect correctly and auth fails. Same behavior in Core regardless of OS.
* Miscellaneous
  * Added: `OutputType` to all functions that return standard objects.
  • Loading branch information
scrthq authored Dec 26, 2018
2 parents 6a13459 + 5845e62 commit ac1a0c5
Show file tree
Hide file tree
Showing 121 changed files with 908 additions and 765 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

* [Changelog](#changelog)
* [2.21.3](#2213)
* [2.21.2](#2212)
* [2.21.1](#2211)
* [2.21.0](#2210)
Expand Down Expand Up @@ -67,6 +68,13 @@

***

## 2.21.3

* [Issue #131](https://github.com/scrthq/PSGSuite/issues/131)
* Fixed: Changed `CodeReceiver` to use `PromptCodeReceiver` when client is PowerShell Core, as `LocalServerCodeReceiver` does not appear to redirect correctly and auth fails. Same behavior in Core regardless of OS.
* Miscellaneous
* Added: `OutputType` to all functions that return standard objects.

## 2.21.2

* [Issue #136](https://github.com/scrthq/PSGSuite/issues/136)
Expand Down
2 changes: 1 addition & 1 deletion PSGSuite/PSGSuite.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSGSuite.psm1'

# Version number of this module.
ModuleVersion = '2.21.2'
ModuleVersion = '2.21.3'

# ID used to uniquely identify this module
GUID = '9d751152-e83e-40bb-a6db-4c329092aaec'
Expand Down
2 changes: 1 addition & 1 deletion PSGSuite/Public/Authentication/Get-GSToken.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Get-GSToken {
$AdminEmail = $Script:PSGSuite.AdminEmail
)
try {
Write-Verbose "Acquiring access token..."
Write-Verbose "Acquiring access token"
$serviceParams = @{
Scope = $Scopes
ServiceType = 'Google.Apis.Gmail.v1.GmailService'
Expand Down
48 changes: 29 additions & 19 deletions PSGSuite/Public/Authentication/New-GoogleService.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ function New-GoogleService {
$User = $script:PSGSuite.AdminEmail
)
Process {
try {
if ($script:PSGSuite.P12KeyPath) {
if ($script:PSGSuite.P12KeyPath) {
try {
Write-Verbose "Building ServiceAccountCredential from P12Key as user '$User'"
$certificate = New-Object 'System.Security.Cryptography.X509Certificates.X509Certificate2' -ArgumentList (Resolve-Path $script:PSGSuite.P12KeyPath),"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
}
User = $User
Scopes = [string[]]$Scope
}
).FromCertificate($certificate)
}
elseif ($script:PSGSuite.ClientSecretsPath -or $script:PSGSuite.ClientSecrets) {
catch {
$PSCmdlet.ThrowTerminatingError($_)
}
}
elseif ($script:PSGSuite.ClientSecretsPath -or $script:PSGSuite.ClientSecrets) {
try {
$ClientSecretsScopes = @(
'https://www.google.com/m8/feeds'
'https://mail.google.com'
Expand All @@ -35,33 +40,38 @@ function New-GoogleService {
'https://www.googleapis.com/auth/tasks'
'https://www.googleapis.com/auth/tasks.readonly'
)
if (!$script:PSGSuite.ClientSecrets) {
if (-not $script:PSGSuite.ClientSecrets) {
$script:PSGSuite.ClientSecrets = (Get-Content $script:PSGSuite.ClientSecretsPath -Raw)
Set-PSGSuiteConfig -ConfigName $script:PSGSuite.ConfigName -ClientSecretsPath $script:PSGSuite.ClientSecretsPath -Verbose:$false
}
Write-Verbose "Building UserCredentials from ClientSecrets as user '$User'"
$stream = New-Object System.IO.MemoryStream $([System.Text.Encoding]::ASCII.GetBytes(($script:PSGSuite.ClientSecrets))),$null
$credPath = Join-Path (Resolve-Path (Join-Path "~" ".scrthq")) "PSGSuite"
Write-Verbose "Building UserCredentials from ClientSecrets as user '$User' and prompting for authorization if necessary."
$stream = New-Object System.IO.MemoryStream $([System.Text.Encoding]::ASCII.GetBytes(($script:PSGSuite.ClientSecrets))),$null
$credential = [Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker]::AuthorizeAsync(
[Google.Apis.Auth.OAuth2.GoogleClientSecrets]::Load($stream).Secrets,
[string[]]$ClientSecretsScopes,
$User,
[System.Threading.CancellationToken]::None,
[Google.Apis.Util.Store.FileDataStore]::new($credPath,$true)
[Google.Apis.Util.Store.FileDataStore]::new($credPath,$true),
$(if($PSVersionTable.PSVersion.Major -gt 5){New-Object 'Google.Apis.Auth.OAuth2.PromptCodeReceiver'}else{New-Object 'Google.Apis.Auth.OAuth2.LocalServerCodeReceiver'})
).Result
$stream.Close()
}
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."))
catch {
$PSCmdlet.ThrowTerminatingError($_)
}
New-Object "$ServiceType" (New-Object 'Google.Apis.Services.BaseClientService+Initializer' -Property @{
HttpClientInitializer = $credential
ApplicationName = "PSGSuite - $env:USERNAME"
finally {
if ($stream) {
$stream.Close()
}
)
}
}
catch {
$PSCmdlet.ThrowTerminatingError($_)
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."))
}
New-Object "$ServiceType" (New-Object 'Google.Apis.Services.BaseClientService+Initializer' -Property @{
HttpClientInitializer = $credential
ApplicationName = "PSGSuite - $env:USERNAME"
}
)
}
}
35 changes: 18 additions & 17 deletions PSGSuite/Public/Calendar/Add-GSCalendarSubscription.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,64 @@ function Add-GSCalendarSubscription {
<#
.SYNOPSIS
Adds a calendar to a users calendar list (aka subscribes to the specified calendar)
.DESCRIPTION
Adds a calendar to a users calendar list (aka subscribes to the specified calendar)
.PARAMETER User
The primary email or UserID of the user. You can exclude the '@domain.com' to insert the Domain in the config or use the special 'me' to indicate the AdminEmail in the config.
.PARAMETER CalendarID
The calendar ID of the calendar you would like to subscribe the user to
.PARAMETER Selected
Whether the calendar content shows up in the calendar UI. Optional. The default is False.
.PARAMETER Hidden
Whether the calendar has been hidden from the list. Optional. The default is False.
.PARAMETER DefaultReminderMethod
The method used by this reminder. Defaults to email.
Possible values are:
* "email" - Reminders are sent via email.
* "sms" - Reminders are sent via SMS. These are only available for G Suite customers. Requests to set SMS reminders for other account types are ignored.
* "popup" - Reminders are sent via a UI popup.
.PARAMETER DefaultReminderMinutes
Number of minutes before the start of the event when the reminder should trigger. Defaults to 30 minutes.
Valid values are between 0 and 40320 (4 weeks in minutes).
.PARAMETER DefaultNotificationMethod
The method used to deliver the notification. Defaults to email.
Possible values are:
* "email" - Reminders are sent via email.
* "sms" - Reminders are sent via SMS. This value is read-only and is ignored on inserts and updates. SMS reminders are only available for G Suite customers.
.PARAMETER DefaultNotificationType
The type of notification. Defaults to eventChange.
Possible values are:
* "eventCreation" - Notification sent when a new event is put on the calendar.
* "eventChange" - Notification sent when an event is changed.
* "eventCancellation" - Notification sent when an event is cancelled.
* "eventResponse" - Notification sent when an event is changed.
* "agenda" - An agenda with the events of the day (sent out in the morning).
.PARAMETER Color
The color of the calendar.
.PARAMETER SummaryOverride
The summary that the authenticated user has set for this calendar.
.EXAMPLE
Add-GSCalendarSubscription -User me -CalendarId [email protected] -Selected -Color Cyan
Adds the calendar '[email protected]' to the AdminEmail user's calendar list
#>
[OutputType('Google.Apis.Calendar.v3.Data.CalendarListEntry')]
[cmdletbinding()]
Param
(
Expand Down Expand Up @@ -172,4 +173,4 @@ function Add-GSCalendarSubscription {
}
}
}
}
}
17 changes: 9 additions & 8 deletions PSGSuite/Public/Calendar/Get-GSCalendarACL.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ function Get-GSCalendarACL {
<#
.SYNOPSIS
Gets the ACL calendar for a calendar
.DESCRIPTION
Gets the ACL for a calendar
Gets the ACL for a calendar
.PARAMETER User
The primary email or UserID of the user. You can exclude the '@domain.com' to insert the Domain in the config or use the special 'me' to indicate the AdminEmail in the config.
Defaults to the AdminEmail in the config
.PARAMETER CalendarId
The calendar ID of the calendar you would like to list ACLS for.
Defaults to the user's primary calendar
.PARAMETER RuleId
The Id of the Rule you would like to retrieve specifically. Leave empty to return the full ACL list instead.
.PARAMETER PageSize
Maximum number of events returned on one result page.
.EXAMPLE
Get-GSCalendarACL -User me -CalendarID "primary"
This gets the ACL on the primary calendar of the AdminUser.
#>
[OutputType('Google.Apis.Calendar.v3.Data.AclRule')]
[cmdletbinding(DefaultParameterSetName = 'List')]
Param
(
Expand Down Expand Up @@ -107,4 +108,4 @@ function Get-GSCalendarACL {
}
}
}
}
}
1 change: 1 addition & 0 deletions PSGSuite/Public/Calendar/Get-GSCalendarEvent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function Get-GSCalendarEvent {
This gets the single events on the primary calendar of the Admin for the week of Jan 21-28, 2018.
#>
[OutputType('Google.Apis.Calendar.v3.Data.Event')]
[cmdletbinding(DefaultParameterSetName = "List")]
Param
(
Expand Down
11 changes: 6 additions & 5 deletions PSGSuite/Public/Calendar/Get-GSCalendarSubscription.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@ function Get-GSCalendarSubscription {
<#
.SYNOPSIS
Gets a subscribed calendar from a users calendar list. Returns the full calendar list if no CalendarId is specified.
.DESCRIPTION
Gets a subscribed calendar from a users calendar list. Returns the full calendar list if no CalendarId is specified.
.PARAMETER User
The primary email or UserID of the user. You can exclude the '@domain.com' to insert the Domain in the config or use the special 'me' to indicate the AdminEmail in the config.
Defaults to the AdminEmail in the config
.PARAMETER CalendarID
The calendar ID of the calendar you would like to get info for. If left blank, returns the list of calendars the user is subscribed to.
.EXAMPLE
Get-GSCalendarSubscription
Gets the AdminEmail user's calendar list
#>
[OutputType('Google.Apis.Calendar.v3.Data.CalendarListEntry')]
[cmdletbinding()]
Param
(
Expand Down Expand Up @@ -79,4 +80,4 @@ function Get-GSCalendarSubscription {
}
}
}
}
}
1 change: 1 addition & 0 deletions PSGSuite/Public/Calendar/New-GSCalendarACL.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ function New-GSCalendarACL {
Gives [email protected] reader access to jennyappleseed's calendar.
#>
[OutputType('Google.Apis.Calendar.v3.Data.AclRule')]
[cmdletbinding(DefaultParameterSetName = "AttendeeEmails")]
Param
(
Expand Down
1 change: 1 addition & 0 deletions PSGSuite/Public/Calendar/New-GSCalendarEvent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function New-GSCalendarEvent {
Creates an event titled "Go to the gym" for 9-10PM the day the function is ran.
#>
[OutputType('Google.Apis.Calendar.v3.Data.Event')]
[cmdletbinding(DefaultParameterSetName = "AttendeeEmails")]
Param
(
Expand Down
1 change: 1 addition & 0 deletions PSGSuite/Public/Calendar/Update-GSCalendarEvent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function Update-GSCalendarEvent {
Creates an event titled "Go to the gym" for 9-10PM the day the function is ran.
#>
[OutputType('Google.Apis.Calendar.v3.Data.Event')]
[cmdletbinding(DefaultParameterSetName = "AttendeeEmails")]
Param
(
Expand Down
11 changes: 6 additions & 5 deletions PSGSuite/Public/Chat/Get-GSChatMember.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,26 @@ function Get-GSChatMember {
<#
.SYNOPSIS
Gets Chat member information
.DESCRIPTION
Gets Chat member information
.PARAMETER Member
Resource name of the membership to be retrieved, in the form "spaces/members".
Example: spaces/AAAAMpdlehY/members/105115627578887013105
.PARAMETER Space
The resource name of the space for which membership list is to be fetched, in the form "spaces".
Example: spaces/AAAAMpdlehY
.EXAMPLE
Get-GSChatMember -Space 'spaces/AAAAMpdlehY'
Gets the list of human members in the Chat space specified
#>
[OutputType('Google.Apis.HangoutsChat.v1.Data.Membership')]
[cmdletbinding(DefaultParameterSetName = "List")]
Param
(
Expand Down Expand Up @@ -60,7 +61,7 @@ function Get-GSChatMember {
}
List {
foreach ($sp in $Space) {
try {
try {
if ($sp -notlike "spaces/*") {
try {
$sp = Get-GSChatConfig -SpaceName $sp -ErrorAction Stop
Expand Down Expand Up @@ -96,4 +97,4 @@ function Get-GSChatMember {
}
}
}
}
}
Loading

0 comments on commit ac1a0c5

Please sign in to comment.