News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Powershell - JWT connection failing - OAU155 Client id is undefined
Tags: rest api
Mar 13, 2024 at 4:08am   •   2 replies  •  0 likes
Daniel McCullagh

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

2 Answers
answered on Mar 13, 2024 at 7:37am  

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.


 0
answered on Mar 13, 2024 at 8:27am  

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


 0
on Mar 13, 2024 at 10:27am   •  0 likes

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

on Mar 14, 2024 at 2:10am   •  0 likes

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


image.png


on Mar 14, 2024 at 7:23am   •  2 likes

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.

on Mar 14, 2024 at 8:51am   •  0 likes

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

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us