question

Daniel McCullagh avatar image
Daniel McCullagh asked Connor Brice commented

Powershell - JWT connection failing - OAU155 Client id is undefined

Hi,

We are trying to extend our existing PowerShell scripts for new and updating user accounts to include RingCentral. The script already connects successfully to our contact centre and Azure using Bearer tokens.

We've created an account and an app within RingCentral and created a JWT for the sandbox. I'm now trying to connect to the sandbox API, prior to testing the account processes.

Having checked several forum posts, solve the OAU-152 issue by changing the Uri to /authorize instead of /token which the documentation says to use.

Unfortunately, all my attempts now lead to OAU-155 errors (client id is undefined).

Here is my code (with access codes abbreviated):

#Pre-defined access codes
$ClientID = "Wd..."
$ClientSecret = "XK..."
$JWT = "ey..."

#Convert codes
$ClientDetails = $ClientID+":"+$ClientSecret
$EncodedClient = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($ClientDetails))

#Create headers
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.add("Content-Type", "application/x-www-form-urlencoded")
$headers.add("Authorization", "Basic $EncodedClient")

#Make grant type uri-friendly
$GrantType = [uri]::EscapeDataString("urn:ietf:params:oauth:grant-type:jwt-bearer")

#Create body
$body = @{
grant_type = $GrantType
assertion = $JWT
response_type = "code"
}

#Authorise
$response = Invoke-RestMethod -Uri "https://platform.devtest.ringcentral.com/restapi/oauth/authorize" -Method Post -Headers $headers -Body $body

Is this error message telling me that the codes supplied are undefined in RingCentral (but they're listed in our portal) or that the client id is undefined in the request (it's clearly in the request header)?

Any assistance will be gratefully received

Dan

rest api
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered

Can you remove the response_type from the body. Using the JWT token to exchange for an access token and a refresh token, not to get the code as for code flow. Check how it's implemented in e.g. PHP.

1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Daniel McCullagh avatar image
Daniel McCullagh answered Connor Brice commented

Many thanks for your response.

Unfortunately that has only changed the error message. It's now showing as:

ERROR: "errorCode" : "OAU-152",
ERROR: "message" : "Unsupported response type: ",
ERROR: "parameters" : [ {
ERROR: "parameterName" : "response_type",
ERROR: "parameterValue" : ""
ERROR: } ]

(Shortened slightly for brevity. Nothing else present except repeats)

I have also looked through the PHP example and (if I'm translating it correctly) then for the core of the authenticate method, the request looks the same as what I'm using, except for the endpoint. I've tried to use /restapi/oauth/token again, and with this endpoint received the following error:

ERROR: "error" : "invalid_request",
ERROR: "errors" : [ {
ERROR: "errorCode" : "OAU-250",
ERROR: "message" : "Unsupported grant type"
ERROR: } ],

4 comments
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image Phong Vu ♦♦ commented ·

This means that your app is not JWT flow type. What is the app client id?

0 Likes 0 ·
Daniel McCullagh avatar image Daniel McCullagh Phong Vu ♦♦ commented ·

Client ID is WdlswaNW7IibjHvCUq2J9h and is definitely JWT flow, per the picture


image.png


0 Likes 0 ·
image.png (199.9 KiB)
Phong Vu avatar image Phong Vu ♦♦ Daniel McCullagh commented ·

Thanks for sharing the client id. The app auth flow is correct then.

Can you check this out to see if it would also fix your problem.

2 Likes 2 ·
Show more comments

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys