article

vb avatar image
vb Posted · · Leonard leWang edited ·

Why does OAuth return "unauthorized for this grant type" error?

Are you receiving the following error when you call the /oauth/token API to authorize your application?

{
                 
"error": "unauthorized_client"
"error_description": "Unauthorized for this grant type"
}

To fix this problem, check the following:

Is your "application type" ==> "Web/UI based" or "browser-based application?"

If the answer is yes you will need to follow the 3 legged OAuth flow to authorize your application.

The authorization code flow provides the following benefits:

  • a consistent and trusted UI
  • integrated password reset
  • integrated single sign-on (SSO) via SAML support

For more information please check out the following:

topic-defaultfrequently asked
6 comments
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I'm also getting this exact same error using Advanced REST client and vb.net desktop application.
0 Likes 0 · ·
Hi Duane,

Could you please check the application type, login to the developer portal (  https://developer.ringcentral.com ) and click on the application and under settings you should see the "Platform Type" . If the platform type is any one of below :
  • Browser-Based
  • Server-Web
  • Server-Only
Then you would need to follow the OAuth 2.0 Code flow for authentication. You could find more information and sample codes here :  https://devcommunity.ringcentral.com/ringcentraldev/topics/using-oauth-2-0-authorization-code-grant-...
0 Likes 0 · ·
the information here is telling us what OAuth 2.0 is, not how to use it. Are there any resources that help new developers actually USE this auth type? 
1 Like 1 · ·
Hi,

It's a vb.net desktop application. In Platform Type I have Desktop/Windows.

I'm using  Resource Owner Password Credentials Flow (ROPC), also named  Password Flow.

Using the SDK c# code tests from RingCentral, it works fine. However, running very similar .net 2.0 code it doesn't. Also, running the RingCentral API Explorer and Advanced REST client doesn't work. Here's the code I'm using:


        Dim client As New WebClient()        
        Dim parameters As String = "grant_type=password" &
                                   "&username=15623520324" &
                                   "&extension=101" &
                                   "&password=" & password
        Dim URL As String = GetUrl("restapi/oauth/token")
        client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded;charset=UTF-8")
        client.Headers.Add(HttpRequestHeader.Authorization, "Basic " & GetApiKey())
        Dim result As String = client.UploadString(URL, "POST", System.Web.HttpUtility.UrlEncode(parameters))
        Assert.NotNull(result)
        Return result




0 Likes 0 · ·
Hi, i m trying to use JS Liberary  but getting same error. if some one could guide it would be great help my code as below:

$(document).ready(function() {
 var RC_SERVER_PRODUCTION = ' https://platform.ringcentral.com';
 var RC_SERVER_SANDBOX = ' https://platform.devtest.ringcentral.com';
 //var RC_SERVER_SAOX = ' https://service.devtest.ringcentral.co.uk';
 var rcsdk = new RingCentral.SDK({
  server : RC_SERVER_SANDBOX,
  appKey : 'GXXXXXXXXXXXXXX',
  appSecret : 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
 });
 var platform = rcsdk.platform();
 rcsdk.platform()
    .login({
        username: '+4420377136XX', // phone number in full format which is given under sandbox credentials

        extension: '301', // Admin default

        password: 'XXXXXXXXXXXXX' // Here my ringcentral developer account password

    })
    .then(function(response) {
          // your code here
          console.log(response);
    })
    .catch(function(e) {
        alert(e.message  + 'Server cannot authorize user');
    });
});
0 Likes 0 · ·
The following works fine for me. Maybe it will help.

--
Public Const RingCentralTokenURI = " https://platform.ringcentral.com/restapi/oauth/token "
Public Const LoginUserName = "%2B18185555555"
Public Const LoginPassword = "mypassword"
----

Dim httpRequest As New MSXML2.XMLHTTP
Dim PayLoad As String

PayLoad = "grant_type=password&username=" & LoginUserName & "&extension=119&" & "password=" & LoginPassword
httpRequest.Open "POST", RingCentralTokenURI, False
   
httpRequest.setRequestHeader "Authorization", "Basic xxxxxxxxxxxxxxxxxxx"    httpRequest.setRequestHeader "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"
   
httpRequest.Send PayLoad
   
Access_Token = "Bearer " & Mid(Mid(httpRequest.responseText, InStr(1, httpRequest.responseText, """access_token"" : """) + 18), _
        1, InStr(1, Mid(httpRequest.responseText, InStr(1, httpRequest.responseText, """access_token"" : """) + 18), """,") - 1)

 Debug.Print Access_Token
   



0 Likes 0 · ·

Article

Contributors

Leonard3223650020 contributed to this article ByrneReese contributed to this article vb contributed to this article

Related Articles