Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to connect with new PSZoom version #82

Open
AstroFish849 opened this issue Dec 8, 2022 · 9 comments
Open

Unable to connect with new PSZoom version #82

AstroFish849 opened this issue Dec 8, 2022 · 9 comments

Comments

@AstroFish849
Copy link

AstroFish849 commented Dec 8, 2022

I'm getting the error
ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
At C:\Users\User\Documents\WindowsPowerShell\Modules\PSZoom\2.0.1.0\Public\Utils\New-OAuthToken.ps1:78 char:35
$token = ($response. Content | ConvertFrom-Json).access_token

Connect-PSZoom : Unable to retrieve token for account ID xxxxx.

I'm using the command
Connect-PSZoom -AccountID 'XXXX' -ClientID 'XXXX' -ClientSecret 'XXXX'

These settings are from the new Server-to-Server OAuth app I've created on Zoom.

What am I doing wrong?

@JosephMcEvoy
Copy link
Owner

The command looks well formatted to me. I tested 2.0.1.0 in PowerShell 5 and 7, and it's working as suspected. I also tried entering wrong credentials and the same error was returned. I suspect it's with how the app was set up or the credentials are not correct.

@AstroFish849
Copy link
Author

I've re-created the app and still getting the same error
ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.

@JosephMcEvoy
Copy link
Owner

I would try making the calls using a plain powershell script or even testing your app with Postman. See https://marketplace.zoom.us/docs/guides/guides/postman/using-postman-to-test-zoom-apis/. The script at the bottom of this comment should return the following when succesful:

New-OAuthToken @params
VERBOSE: POST with 0-byte payload
VERBOSE: received -byte response of content type application/json
VERBOSE: Acquired token.
System.Security.SecureString

or error:

New-OAuthToken @params
VERBOSE: POST with 0-byte payload
VERBOSE: received -byte response of content type application/json

Name                           Value
----                           -----
error                          invalid_client
reason                         Invalid client_id or client_secret
VERBOSE: Acquired token.

Here's the script:

function New-OAuthToken {
    <#
    .SYNOPSIS
    Retrieves the Zoom OAuth API token

    .PARAMETER ClientID
    Client ID of the Zoom App

    .PARAMETER ClientSecret
    Client Secret of the Zoom App

    .PARAMETER AccountID
    Account ID of the Zoom App

    .OUTPUTS
    Zoom API Response
    
    #>

    [CmdletBinding()]
    param (
        [Parameter(valuefrompipeline = $true, mandatory = $true, HelpMessage = "Enter Zoom App Account ID", Position = 0)]
        [String]
        $AccountID,

        [Parameter(valuefrompipeline = $true, mandatory = $true, HelpMessage = "Enter Zoom App Client ID:", Position = 1)]
        [String]
        $ClientID,

        [Parameter(valuefrompipeline = $true, mandatory = $true, HelpMessage = "Enter Zoom App Client Secret:", Position = 2)]
        [String]
        $ClientSecret

    )

    $uri = "https://zoom.us/oauth/token?grant_type=account_credentials&account_id={0}" -f $AccountID

    #Encoding of the client data
    $IDSecret = $ClientID + ":" + $ClientSecret 
    $EncodedIDSecret = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($IDSecret))

    $headers = @{
        "Authorization" = "Basic $EncodedIDSecret"  
    }
            
    try {
        $response = Invoke-WebRequest -uri $uri -headers $headers -Method Post -UseBasicParsing
    } catch {
        ConvertFrom-Json $_.errorDetails -AsHashtable
    }

    Write-Verbose 'Acquired token.'
    $token = ($response.content | ConvertFrom-Json).access_token
    $token = ConvertTo-SecureString -String $token -AsPlainText -Force
    Write-Output $token
}

$params = @{
    AccountID = '1234567891234567890123'
    ClientID = '12345678901234567890'
    ClientSecret = '12345678901234567890123456789012'
    Verbose = $True
}

New-OAuthToken @params

@JosephMcEvoy
Copy link
Owner

Ah, this is likely related to internet explorer not being on your local computer. I still have to push those changes to the powershell gallery.

@JosephMcEvoy
Copy link
Owner

The changes are pushed to the gallery. Please update your module and try again.

@AstroFish849
Copy link
Author

Hey,
So running that script in Powershell works but just plain running the command Connect-PSZoom -AccountID 'XXXX' -ClientID 'XXXX' -ClientSecret 'XXXX' in powershell doesn't

Annoyingly I'm using Rundeck and not Postman - I'll do some Googling on this one

@AMARABDELLI
Copy link

Hello @JosephMcEvoy
I'm running into the same issue @AstroFish849 ran into. Were you guys able to find a solution?
image

@kaopectate
Copy link

ran that test "new-oauthtoken" script and it errored out on my win 10 machine, but worked fine on server. i believe this is due to changes in behavior of IE. when launched on win 10 machine it closes and launches new edge.

Also why are you not just using Invoke-RestMethod ?

@jwong00
Copy link

jwong00 commented Jan 16, 2024

I think this is the issue I'm experiencing at the moment. It's not clear to me why IE is relevant to this issue, could someone please explain?

I've written a little test script that attempts the Connect-PSZoom with the accountid, clientid, and client secret. On my own machine, it works. On the server, it throws the same error messages others have screenshotted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants