Skip to main content

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

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.


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: } ],


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


Reply