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
Console app trying to JWT authorize in the sandbox and getting Unauthorized for this grant type
Tags: authentication, developer sandbox
Feb 27, 2022 at 1:24pm   •   2 replies  •  0 likes
A Feibus

I swear I set it up right, but it's failing, and I can't figure out where to look. Using C# and latest SDK.

Using Fiddler, I see that the call to https://platform.devtest.ringcentral.com/restapi/oauth/token, with this info:

grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJraWQiOiI4NzYyZjU5OGQwNTk0NGRiODZiZjVjYTk3ODA0NzYwOCIsInR5cCI6IkpXVCIsImFsZyI6IlJTMjU2In0..... (not putting the whole token here, but it's in the parms).

Says it's using TLS1.2, so that's right. Returns:

{
  "error" : "unauthorized_client",
  "errors" : [ {
    "errorCode" : "OAU-251",
    "message" : "Unauthorized for this grant type"
  } ],
  "error_description" : "Unauthorized for this grant type"
}

App is set up to use JWT (I also tried setting to password auth with the right user/ext/password and that returned the same outcome). The JWT token is correct. What did I do wrong? Once the 400 happens, authorize call hangs.

Thanks in advance.

on Feb 28, 2022 at 7:38am   •  0 likes

Before investigating your case, can you give me the app client id so I can have a look at the app settings.

on Feb 28, 2022 at 7:40am   •  0 likes

1A_7xhOcR1OKhkuFetzZfQ


thank you!

1 Answer
answered on Feb 28, 2022 at 8:21am  

Can you try it now. I changed the app scope from public to private as the JWT was personal and the platform type is server-only. Let me know if your app must be a public app.


 0
on Feb 28, 2022 at 8:36am   •  0 likes

Halfway there maybe.

Getting a 200 response with a token, so that part looks right (see below). But, the .Authorize call

rc.Authorize(ConfigurationManager.AppSettings["RC Token"]).Wait();

isn't coming back from the Wait() still. What else is it waiting on?

The plan is that this customer is the only one to ever run it, so private is perfect.

In case you need it, Fiddler shows the response came back with something like this:

{
  "access_token" : "U0pDMTJQMDFQQVMw....",
  "token_type" : "bearer",
  "expires_in" : 3600,
  "refresh_token" : "U0pDMTJQMDFQQVMw....",
  "refresh_token_expires_in" : 604800,
  "scope" : "Faxes",
  "owner_id" : "714822005",
  "endpoint_id" : "y-janHULTiaQuTUOmX6gbg"
}
on Feb 28, 2022 at 9:41am   •  0 likes

if it's not returned, how do you get the tokens then? Pls share some code (w/o sensitive info)

on Feb 28, 2022 at 9:55am   •  0 likes

Using Fiddler to see the requests and responses.

Code is inside an asynchronous routine, and looks like this, and I'm seeing the packets for the .Authorize() call, but the .Wait just sits and never returns.

var rc = new RestClient(ConfigurationManager.AppSettings["RC Client"], ConfigurationManager.AppSettings["RC Secret"], ConfigurationManager.AppSettings["RC URL"]);
rc.Authorize(ConfigurationManager.AppSettings["RC Token"]).Wait();
on Feb 28, 2022 at 10:37am   •  0 likes

It's prone to cause dead lock if you mix .Wait()/.Result and await. But this is a pure C# programming issue, not related to RingCentral.

And I believe if you try to authorize via password instead of JWT, you app will be stuck too.

on Feb 28, 2022 at 10:47am   •  1 likes

You are correct, it was a deadlock, inside a Winforms UI event, putting Task.Run(async() => around it solved the problem, thank you!

on Feb 28, 2022 at 9:57am   •  0 likes

Sorry, SYNCHRONOUS routine. Not async.

on Feb 28, 2022 at 10:35am   •  1 likes

I believe it's a C# deadlock. https://stackoverflow.com/questions/15021304/an-async-await-example-that-causes-a-deadlock

I would avoid using .Wait() and stick to await.



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