I keep getting a 502 Bad Gateway error when attempting to obtain an access token using JWT, but am not sure why this is happening.
Powershell code:
$RC_SERVER_URL="https://platform.devtest.ringcentral.com"
$RC_CLIENT_ID="T2......"Â # Copied from the app I created
$RC_CLIENT_SECRET="v8d......"Â # Copied from the app I created
$RC_JWT_TOKENÂ =Â "eyJra....."Â # Created under My Account > Credentials and given specific authorization to the app Client ID above
# as per https://developers.ringcentral.com/guide/authentication/jwt-flow#technical-discussion
$splat = @{
   Method = "POST"
   Uri   = $RC_SERVER_URL + "/restapi/oauth/token"
   ContentType = 'application/x-www-form-urlencoded'
   headers = @{ Â
    Accept = 'application/json'
     Authorization = 'Basic ' + Convert]::ToBase64String( Text.Encoding]::Unicode.GetBytes("${RC_CLIENT_ID}:${RC_CLIENT_SECRET}"))
  }
   body  = @{
     grant_type = 'urn:ietf:params:oauth:grant-type:jwt-bearer'
     assertion = $RC_JWT_TOKEN
  }
}
$Response = Invoke-RestMethod @splat
The object looks good and isn't missing anything:
$splat
Name              Value
---- Â Â Â Â Â Â Â Â Â Â Â Â Â -----
ContentType           application/x-www-form-urlencoded
Method             POST
body              {assertion, grant_type}
headers             {Accept, Authorization}
Uri               https://platform.devtest.ringcentral.com/restapi/oauth/token
PS C:scriptsGet-RingCentralData> $splat.headers
Name              Value
---- Â Â Â Â Â Â Â Â Â Â Â Â Â -----
Accept application/json
Authorization          Basic VAAyAF...
PS C:scriptsGet-RingCentralData> $splat.body
Name              Value
---- Â Â Â Â Â Â Â Â Â Â Â Â Â -----
assertion            eyJra...
grant_type           urn:ietf:params:oauth:grant-type:jwt-bearer
The response I get when executing this is:
$Response = Invoke-RestMethod @splat
Invoke-RestMethod : The remote server returned an error: (502) Bad Gateway.
At line:1 char:13
+ $Response = Invoke-RestMethod @splat
+ Â Â Â Â Â Â ~~~~~~~~~~~~~~~~~~~~~~~~
  + CategoryInfo      : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) eInvoke-RestMethod], WebException
  + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Any ideas why this might be happening?