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
OAU-251 error - Unauthorized for this grant type
Tags: oauth2, authentication, oauth
Jun 7, 2023 at 7:55am   •   1 replies  •  0 likes
Mousa Khalil

I want to generate a JWT for my users, hence, I used the following endpoint alongside the appropriate headers and body, but in order to provide the main JWT for the assertion I was required to created manually for the account. How could I automate it, so that I can create any JWTs using API requests? I tried using password grant_type but it did not work, and throws an OAU-251 error - Unauthorized for this grant type.

Sandbox # +12678284935
Client ID jfEaGJSpQgaMYwr8Q-O1Zg


The following code snippet works fine, but I want to automatically generate the main JWT.

def getAccessToken(username, extension, password, server, client_id, client_secret):
    url = f"{server}/restapi/oauth/token"
    data = {
        "grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
        "username": f"{username}*{extension}",
        "password": password,
        "assertion":"eyJraWQiOiI4NzYyZjU5OGQ..."
    }
    
    headers = {
        "Content-Type": "application/x-www-form-urlencoded",
        "Authorization": "Basic " + base64.b64encode(f"{client_id}:{client_secret}".encode("utf-8")).decode("utf-8")
    }
    
    res = requests.post(url, headers=headers, data=data)
    return (res.json())


1 Answer
answered on Jun 7, 2023 at 8:06am  

Please refer to our Dev Guide documentation for instruction how to authenticate with a JWT token. The body data does not take others than just the grant_type and the assertion.


 0



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