# Converting JWT call to Oauth = 401

**URL:** <https://devforum.zoom.us/t/converting-jwt-call-to-oauth-401/90144>\
**Category:** API and Webhooks\
**Created:** [June 14, 2023, 12:15pm UTC](https://devforum.zoom.us/t/converting-jwt-call-to-oauth-401/90144 "2023-06-14T12:15:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dolphin65](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@Dolphin65](https://devforum.zoom.us/u/Dolphin65)\
**Post date:** [June 14, 2023, 12:15pm UTC](https://devforum.zoom.us/t/converting-jwt-call-to-oauth-401/90144/1 "2023-06-14T12:15:42Z")

</div>

I am using Powershell to download recorded meetings, and as per JWT October’s deadline, I am attempting to modify the code accordingly. JWT still working, while when passing Oauth token as bearer, system will return 401 (unauthorised).  
I’m wondering if the token format is wrong, or if the token is invalid.

**Initialisation** (working perfectly)

```auto

    $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"  
    }
            
    # Maybe add some error handling
    try {
        $response = Invoke-WebRequest -uri $uri -headers $headers -Method Post
    } catch {
        $_
    }

    Write-Verbose 'Acquired token.'
    
    $token = ($response.content | ConvertFrom-Json).access_token

    $token = ConvertTo-SecureString -String $token -AsPlainText -Force

```

**Download after getting user recording list**  
JWT version (working)

```auto
 # invoke JWT token creation
        $JWT = Generate-JWT -Algorithm 'HS256' -type 'JWT' -Issuer $ZoomApiKey -SecretKey $ZoomApiSecret -ValidforSeconds 7200 # was 3200
        # Add token to download URL
        $jwtURL = $item.URL + "?access_token=" + $JWT
        $outfile = "$($downloadsFolder)\$fileName"
        $StartDate=(GET-DATE)
        Write-Host "Downloading to $outfile [Zoom Time: $($item.StartDate)] - "+$(Format-Bytes $item.Size)+"..."

        # Download recording
        try {
            $ProgressPreference = 'SilentlyContinue'
           $r = Invoke-WebRequest -Uri $jwtURL -OutFile $outfile
            $a = [int]$r.StatusCode
        }
        catch {
            $a = [int]$_.Exception.Response.StatusCode
        }

```

**Oauth download** (not working)

```auto

        $bearer_token = (ConvertFrom-SecureString $Global:PSZoomToken)
        $headers = @{Authorization = "Bearer $bearer_token"}
        $outfile = "$($downloadsFolder)\$fileName"
        $StartDate=(GET-DATE)
        Write-Host "Downloading to $outfile [Zoom Time: $($item.StartDate)] - "+$(Format-Bytes $item.Size)+"..."

        # Download recording
        try {
            $ProgressPreference = 'SilentlyContinue'
            $r = Invoke-RestMethod -Uri $item.URL -Method 'Post' -OutFile $outfile -Headers $headers -UseBasicParsing 
            $a = [int]$r.StatusCode
        }
        catch {
            $a = [int]$_.Exception.Response.StatusCode
        }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [June 17, 2024, 3:52am UTC](https://devforum.zoom.us/t/converting-jwt-call-to-oauth-401/90144/2 "2024-06-17T03:52:21Z")

</div>

Closed on June 17, 2024, 3:52am UTC

This topic was automatically closed 368 days after the last reply. New replies are no longer allowed.
