C# SDK Cannot Authorize - Bad Request

  • 1
  • Problem
  • Updated 4 weeks ago
  • (Edited)
Private App Authorization
Platform Type: Server/BOT (plan to surface MS BOT Framework in Glip)
Permissions: Glip, Read Contacts, Read Messages

I'm using the RingCentral Client C# SDK as shown on Github to authorize:
var oToken = await oRestClient.Authorize(cUserName, "", cPassword);

And I keep getting the same error: {"Call failed with status code 400 (Bad Request): POST https://platform.devtest.ringcentral.com/restapi/oauth/token"}

WWW-Authenticate: Bearer realm="RingCentral REST API", error="unauthorized_client", error_description="Unauthorized for this grant type"

I'm using the phone number and password from: https://developer.ringcentral.com also I can log into my RingCentral.com account with my credentials so why is authentication failing?

StackTtrace:
Message: Call failed with status code 400 (Bad Request): POST https://platform.devtest.ringcentral.com/restapi/oauth/token
 StackTrace:   at Flurl.Http.FlurlRequest.<HandleExceptionAsync>d__23.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Flurl.Http.FlurlRequest.<SendAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Flurl.Http.HttpResponseMessageExtensions.<ReceiveJson>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at RingCentral.RestClient.<Authorize>d__39.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at RESTAPI_Testing.Program.<Main>d__0.MoveNext() in ...Program.cs:line 53

Photo of IT Admin

IT Admin

  • 90 Points 75 badge 2x thumb
  • very frustrated

Posted 1 month ago

  • 1
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,152 Points 5k badge 2x thumb
  **Q: Why does OAuth return "unauthorized for this grant type" error?**

  **A:** The error "unauthorized for grant type" occurs when your application is attempting to use an OAuth grant type that it is not approved to use. This often happens when your app requires the Authorization Code Flow but is attempting to use the Password Flow. See below for information in implementing Authorization Code Flow. For more information see [this Developer Community article](https://devcommunity.ringcentral.com/ringcentraldev/topics/unauthorized-for-this-grant-type-error).


  **Q: How to deal with "Unauthorized for this grant type" issue?**
  
  **A:** It probably means your app doesn't support password authorization flow. Please logon https://developer.ringcentral.com and confirm that your app has the following configuration: https://cloud.githubusercontent.com/assets/733544/18026560/b93e5356-6c7d-11e6-92a9-d35d28325e69.png
Photo of IT Admin

IT Admin

  • 90 Points 75 badge 2x thumb
If my users are already authenticated via Glip/Ring Central App. Why can I not access posts and groups via the admin username password.  At this point I do not have an additional server component for authentication. 

1) Can this not be handled by the C# SDK? 

Also, documentation states
Please note: Glip App (mobile or desktop) does NOT have:

  • support for the RingCentral Sandbox API (cannot switch to 'developer mode');

  • does not have a 'Sandbox version'

2) Does this mean I cannot talk to the API from sandbox app?

3) Also if I do not have an authentication/authorization server other that Glip right now do I even need an OAuth Redirect URI?

Photo of Tyler Long

Tyler Long, Official Rep

  • 7,912 Points 5k badge 2x thumb
You cannot access other users's Glip posts/groups even you are admin. It is by design.

You can try other SDK if you don't like the C# one. We have SDKs for popular languages.

You CAN talk to Glip API from sandbox APP. But your sandbox app can only access sandbox env. (production and sandbox are separated env)

You can leave oauth redirect uri field empty and fill it later.
Photo of IT Admin

IT Admin

  • 90 Points 75 badge 2x thumb
Please note: I do not have an issue with the C# API. For the Platform Type I am building, RingCentral locks me into the Authorization Code "Authorization Flow type" for the Bot App I am using so:
1) Should I create a new app as other or Server-only (No-UI)?
2) More importantly can I add the Glip permission to my app
3) Will I still be able to integrate it into Glip?
Photo of Phong Vu

Phong Vu, Devangelist

  • 3,082 Points 3k badge 2x thumb
Hi IT Admin,

To test your Glip app on sandbox, use this link instead of the App. https://glip-app.devtest.ringcentral.com/

Hope this helps,
+ Phong
Photo of Tyler Long

Tyler Long, Official Rep

  • 8,152 Points 5k badge 2x thumb
1) Should I create a new app as other or Server-only (No-UI)? 

Generally you should stick to Server/bot app type if you are building a bot. This is because, we provide never expire tokens for bot apps. So you can forget about bot token refresh.


2) More importantly can I add the Glip permission to my app

Yes, when you create the app, you can specify Glip permission (no matter what app type you choose). Can't you? Let me know if you have difficulty on this


3) Will I still be able to integrate it into Glip?

Yes I think so but as I said I think you should stick to Server/bot app type.



Why do you dislike Authorization Code "Authorization Flow type" ? Is there anything prevent you from using it?