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?
Client ID is WdlswaNW7IibjHvCUq2J9h and is definitely JWT flow, per the picture
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.
Greetings,
Dans Colleague here,
so adding the UTF-8 to our script like this:
#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; charset=UTF-8") $headers.add("Authorization", "Basic $EncodedClient")
didn't fix it - but when I tried the code written in the thread you linked, it worked just fine and I got a response with a token.
I assume it has something to do with how the header is encoded?
Im sure we can use this,
Thanks for your help :)
A new Community is coming to RingCentral!
Posts are currently read-only as we transition into our new platform.We thank you for your patience
during this downtime.
Try Workflow Builder
Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!Try RingCentral Workflow Builder